Class JsonWriter.Member<T>
java.lang.Object
org.springframework.boot.json.JsonWriter.Member<T>
- Type Parameters:
- T- the member type
- Enclosing interface:
- 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.
- Since:
- 3.4.0
- 
Method SummaryModifier and TypeMethodDescription<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.Membersconfiguration.<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 notnulland 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.
- 
Method Details- 
whenNotNullOnly include this member when its value is notnull.- Returns:
- a JsonWriter.Memberwhich may be configured further
 
- 
whenNotNullOnly include this member when an extracted value is notnull.- Parameters:
- extractor- an function used to extract the value to test
- Returns:
- a JsonWriter.Memberwhich may be configured further
 
- 
whenHasLengthOnly include this member when it is notnulland has atoString()that is not zero length.- Returns:
- a JsonWriter.Memberwhich may be configured further
- See Also:
 
- 
whenNotEmptyOnly include this member when it is not empty (SeeObjectUtils.isEmpty(Object)for details).- Returns:
- a JsonWriter.Memberwhich may be configured further
 
- 
whenNotOnly include this member when the given predicate does not match.- Parameters:
- predicate- the predicate to test
- Returns:
- a JsonWriter.Memberwhich may be configured further
 
- 
whenOnly include this member when the given predicate matches.- Parameters:
- predicate- the predicate to test
- Returns:
- a JsonWriter.Memberwhich may be configured further
 
- 
asAdapt the value by applying the givenFunction.- Type Parameters:
- R- the result type
- Parameters:
- adapter- a- Functionto adapt the value
- Returns:
- a JsonWriter.Memberwhich may be configured further
 
- 
usingExtractedPairspublic <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 }- Type Parameters:
- E- the element type
- Parameters:
- elements- callback used to provide the elements
- extractor- a- JsonWriter.PairExtractorused to extract the name/value pair
- Returns:
- a JsonWriter.Memberwhich may be configured further
- See Also:
 
- 
usingExtractedPairspublic <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 }- Type Parameters:
- E- the element type
- N- the name type
- V- the value type
- Parameters:
- elements- callback used to provide the elements
- nameExtractor-- Functionused to extract the name
- valueExtractor-- Functionused to extract the value
- Returns:
- a JsonWriter.Memberwhich may be configured further
- See Also:
 
- 
usingPairsAdd 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 }- Type Parameters:
- N- the name type
- V- the value type
- Parameters:
- pairs- callback used to provide the pairs
- Returns:
- a JsonWriter.Memberwhich may be configured further
- See Also:
 
- 
usingMembersAdd JSON based on furtherJsonWriter.Membersconfiguration. 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" }- Parameters:
- members- callback to configure the members
- Returns:
- a JsonWriter.Memberwhich may be configured further
- See Also:
 
- 
toString
 
-