Class JsonWriter.Members<T>

java.lang.Object
org.springframework.boot.json.JsonWriter.Members<T>
Type Parameters:
T - the type that will be written
Enclosing interface:
JsonWriter<T>

public static final class JsonWriter.Members<T> extends Object
Callback used to configure JSON members. Individual members can be declared using the various add(...) methods. Typically, members are declared with a "name" and a Function that will extract the value from the instance. Members can also be declared using a static value or a Supplier. The add(String) and add() methods may be used to access the actual instance being written.

Members can be added without a name when a Member.using(...) method is used to complete the definition.

Members can filtered using Member.when methods and adapted to different types using Member.as(...).

  • Method Details

    • add

      public JsonWriter.Member<T> add(String name)
      Add a new member with access to the instance being written.
      Parameters:
      name - the member name
      Returns:
      the added JsonWriter.Member which may be configured further
    • add

      public <V> JsonWriter.Member<V> add(String name, V value)
      Add a new member with a static value.
      Type Parameters:
      V - the value type
      Parameters:
      name - the member name
      value - the member value
      Returns:
      the added JsonWriter.Member which may be configured further
    • add

      public <V> JsonWriter.Member<V> add(String name, Supplier<V> supplier)
      Add a new member with a supplied value.
      Type Parameters:
      V - the value type
      Parameters:
      name - the member name
      supplier - a supplier of the value
      Returns:
      the added JsonWriter.Member which may be configured further
    • add

      public <V> JsonWriter.Member<V> add(String name, Function<T,V> extractor)
      Add a new member with an extracted value.
      Type Parameters:
      V - the value type
      Parameters:
      name - the member name
      extractor - a function to extract the value
      Returns:
      the added JsonWriter.Member which may be configured further
    • add

      public JsonWriter.Member<T> add()
      Add a new member with access to the instance being written. The member is added without a name, so one of the Member.using(...) methods must be used to complete the configuration.
      Returns:
      the added JsonWriter.Member which may be configured further
    • addMapEntries

      public <M extends Map<K, V>, K, V> JsonWriter.Member<M> addMapEntries(Function<T,M> extractor)
      Add all entries from the given Map to the JSON.
      Type Parameters:
      M - the map type
      K - the key type
      V - the value type
      Parameters:
      extractor - a function to extract the map
      Returns:
      the added JsonWriter.Member which may be configured further
    • from

      public <V> JsonWriter.Member<V> from(V value)
      Add members from a static value. One of the Member.using(...) methods must be used to complete the configuration.
      Type Parameters:
      V - the value type
      Parameters:
      value - the member value
      Returns:
      the added JsonWriter.Member which may be configured further
    • from

      public <V> JsonWriter.Member<V> from(Supplier<V> supplier)
      Add members from a supplied value. One of the Member.using(...) methods must be used to complete the configuration.
      Type Parameters:
      V - the value type
      Parameters:
      supplier - a supplier of the value
      Returns:
      the added JsonWriter.Member which may be configured further
    • from

      public <V> JsonWriter.Member<V> from(Function<T,V> extractor)
      Add members from an extracted value. One of the Member.using(...) methods must be used to complete the configuration.
      Type Parameters:
      V - the value type
      Parameters:
      extractor - a function to extract the value
      Returns:
      the added JsonWriter.Member which may be configured further
    • applyingPathFilter

      public void applyingPathFilter(Predicate<JsonWriter.MemberPath> predicate)
      Add a filter that will be used to restrict the members written to the JSON.
      Parameters:
      predicate - the predicate used to filter members
    • applyingNameProcessor

      public void applyingNameProcessor(JsonWriter.NameProcessor nameProcessor)
      Add the a JsonWriter.NameProcessor to be applied when the JSON is written.
      Parameters:
      nameProcessor - the name processor to add
    • applyingValueProcessor

      public void applyingValueProcessor(JsonWriter.ValueProcessor<?> valueProcessor)
      Add the a JsonWriter.ValueProcessor to be applied when the JSON is written.
      Parameters:
      valueProcessor - the value processor to add