Record Class JsonArray<T,U>

java.lang.Object
java.lang.Record
net.tangly.gleam.model.JsonArray<T,U>
Type Parameters:
T - type of the entity owning the field
U - type of the common ancestor for the entities stored in the array
Record Components:
key - name of the property containing the JSON array
getter - getter of the property - returns a collection of items
setter - setter used to add an item to the collection mapping the JSON array
importSelector - selector to identify the type of the collection item based on any discriminator in the JSON array
exportSelector - selector to identify the type of the collection item based on any discriminator of the Java object
All Implemented Interfaces:
JsonField<T,U>

public record JsonArray<T,U>(@NotNull String key, @NotNull Function<T,Collection<U>> getter, @NotNull BiConsumer<T,U> setter, Function<org.json.JSONObject,JsonEntity<?>> importSelector, Function<Object,JsonEntity<?>> exportSelector) extends Record implements JsonField<T,U>
Define a field containing an array of entities. The entities can be of different types but must have a common ancestor.
  • Constructor Details

  • Method Details

    • exports

      public void exports(@NotNull T entity, @NotNull @NotNull org.json.JSONObject object)
      Description copied from interface: JsonField
      Export the JSON value from the associated property after an optional conversion. Multiple JSON values can be written if the object is a complex one.
      Specified by:
      exports in interface JsonField<T,U>
      Parameters:
      entity - entity which property will be exported as TSV value
      object - JSON object to write the TSV value(s)
      See Also:
    • imports

      public void imports(@NotNull T entity, @NotNull @NotNull org.json.JSONObject object)
      Description copied from interface: JsonField
      Import the JSON value and set the associated property after an optional conversion. Multiple JSON values can be used if the object is complex.
      Specified by:
      imports in interface JsonField<T,U>
      Parameters:
      entity - entity which property will be imported and set
      object - JSON object containing the values
      See Also:
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • key

      @NotNull public @NotNull String key()
      Returns the value of the key record component.
      Specified by:
      key in interface JsonField<T,U>
      Returns:
      the value of the key record component
    • getter

      @NotNull public @NotNull Function<T,Collection<U>> getter()
      Returns the value of the getter record component.
      Returns:
      the value of the getter record component
    • setter

      @NotNull public @NotNull BiConsumer<T,U> setter()
      Returns the value of the setter record component.
      Returns:
      the value of the setter record component
    • importSelector

      public Function<org.json.JSONObject,JsonEntity<?>> importSelector()
      Returns the value of the importSelector record component.
      Returns:
      the value of the importSelector record component
    • exportSelector

      public Function<Object,JsonEntity<?>> exportSelector()
      Returns the value of the exportSelector record component.
      Returns:
      the value of the exportSelector record component