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 addSelf(String) and addSelf() 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

    • addSelf

      public JsonWriter.Member<T> addSelf(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
    • addSelf

      public JsonWriter.Member<T> addSelf()
      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
    • add

      public <V> JsonWriter.Member<V> add(V value)
      Add a new member with a static value. The member is added without a name, so 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
    • add

      public <V> JsonWriter.Member<V> add(Supplier<V> supplier)
      Add a new member with a supplied value.The member is added without a name, so 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
    • add

      public <V> JsonWriter.Member<V> add(Function<T,V> extractor)
      Add a new member with an extracted value. The member is added without a name, so 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
    • 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