类 JsonWriter.Member<T>
java.lang.Object
org.springframework.boot.json.JsonWriter.Member<T>
- 类型参数:
T
- the member type
- 封闭接口:
JsonWriter<T>
A member that contributes JSON. Typically, a member will contribute a single
name/value pair based on an extracted value. They may also contribute more complex
JSON structures when configured with one of the
using(...)
methods.
The when(...)
methods may be used to filter a member (omit it entirely from
the JSON). The as(Function)
method can be used to adapt to a different
type.
-
方法概要
修饰符和类型方法说明<R> JsonWriter.Member
<R> Adapt the value by applying the givenFunction
.toString()
<E,
N, V> JsonWriter.Member <T> usingExtractedPairs
(BiConsumer<T, Consumer<E>> elements, Function<E, N> nameExtractor, Function<E, V> valueExtractor) Add JSON name/value pairs by extracting values from a series of elements.<E> JsonWriter.Member
<T> usingExtractedPairs
(BiConsumer<T, Consumer<E>> elements, JsonWriter.PairExtractor<E> extractor) Add JSON name/value pairs by extracting values from a series of elements.usingMembers
(Consumer<JsonWriter.Members<T>> members) Add JSON based on furtherJsonWriter.Members
configuration.<N,
V> JsonWriter.Member <T> usingPairs
(BiConsumer<T, BiConsumer<N, V>> pairs) Add JSON name/value pairs.Only include this member when the given predicate matches.Only include this member when it is notnull
and has atoString()
that is not zero length.Only include this member when the given predicate does not match.Only include this member when it is not empty (SeeObjectUtils.isEmpty(Object)
for details).Only include this member when its value is notnull
.whenNotNull
(Function<T, ?> extractor) Only include this member when an extracted value is notnull
.
-
方法详细资料
-
whenNotNull
Only include this member when its value is notnull
.- 返回:
- a
JsonWriter.Member
which may be configured further
-
whenNotNull
Only include this member when an extracted value is notnull
.- 参数:
extractor
- an function used to extract the value to test- 返回:
- a
JsonWriter.Member
which may be configured further
-
whenHasLength
Only include this member when it is notnull
and has atoString()
that is not zero length.- 返回:
- a
JsonWriter.Member
which may be configured further - 另请参阅:
-
whenNotEmpty
Only include this member when it is not empty (SeeObjectUtils.isEmpty(Object)
for details).- 返回:
- a
JsonWriter.Member
which may be configured further
-
whenNot
Only include this member when the given predicate does not match.- 参数:
predicate
- the predicate to test- 返回:
- a
JsonWriter.Member
which may be configured further
-
when
Only include this member when the given predicate matches.- 参数:
predicate
- the predicate to test- 返回:
- a
JsonWriter.Member
which may be configured further
-
as
Adapt the value by applying the givenFunction
.- 类型参数:
R
- the result type- 参数:
adapter
- aFunction
to adapt the value- 返回:
- a
JsonWriter.Member
which may be configured further
-
usingExtractedPairs
public <E> JsonWriter.Member<T> usingExtractedPairs(BiConsumer<T, Consumer<E>> elements, JsonWriter.PairExtractor<E> extractor) Add JSON name/value pairs by extracting values from a series of elements. Typically used with aIterable.forEach(Consumer)
call, for example:members.add(Event::getTags).usingExtractedPairs(Iterable::forEach, pairExtractor);
When used with a named member, the pairs will be added as a new JSON value object:
{ "name": { "p1": 1, "p2": 2 } }
When used with an unnamed member the pairs will be added to the existing JSON object:{ "p1": 1, "p2": 2 }
- 类型参数:
E
- the element type- 参数:
elements
- callback used to provide the elementsextractor
- aJsonWriter.PairExtractor
used to extract the name/value pair- 返回:
- a
JsonWriter.Member
which may be configured further - 另请参阅:
-
usingExtractedPairs
public <E,N, JsonWriter.Member<T> usingExtractedPairsV> (BiConsumer<T, Consumer<E>> elements, Function<E, N> nameExtractor, Function<E, V> valueExtractor) Add JSON name/value pairs by extracting values from a series of elements. Typically used with aIterable.forEach(Consumer)
call, for example:members.add(Event::getTags).usingExtractedPairs(Iterable::forEach, Tag::getName, Tag::getValue);
When used with a named member, the pairs will be added as a new JSON value object:
{ "name": { "p1": 1, "p2": 2 } }
When used with an unnamed member the pairs will be added to the existing JSON object:{ "p1": 1, "p2": 2 }
- 类型参数:
E
- the element typeN
- the name typeV
- the value type- 参数:
elements
- callback used to provide the elementsnameExtractor
-Function
used to extract the namevalueExtractor
-Function
used to extract the value- 返回:
- a
JsonWriter.Member
which may be configured further - 另请参阅:
-
usingPairs
Add JSON name/value pairs. Typically used with aMap.forEach(BiConsumer)
call, for example:members.add(Event::getLabels).usingPairs(Map::forEach);
When used with a named member, the pairs will be added as a new JSON value object:
{ "name": { "p1": 1, "p2": 2 } }
When used with an unnamed member the pairs will be added to the existing JSON object:{ "p1": 1, "p2": 2 }
- 类型参数:
N
- the name typeV
- the value type- 参数:
pairs
- callback used to provide the pairs- 返回:
- a
JsonWriter.Member
which may be configured further - 另请参阅:
-
usingMembers
Add JSON based on furtherJsonWriter.Members
configuration. For example:members.add(User::getName).usingMembers((personMembers) -> { personMembers.add("first", Name::first); personMembers.add("last", Name::last); });
When used with a named member, the result will be added as a new JSON value object:
{ "name": { "first": "Jane", "last": "Doe" } }
When used with an unnamed member the result will be added to the existing JSON object:{ "first": "John", "last": "Doe" }
- 参数:
members
- callback to configure the members- 返回:
- a
JsonWriter.Member
which may be configured further - 另请参阅:
-
toString
-