Interface FieldSpec<T,V>

Type Parameters:
T - the object type containing this field
V - the field value type

public interface FieldSpec<T,V>
Describes how to access a field on an object — its name, codec, getter, setter, and presence predicate.
  • Method Details

    • name

      String name()
    • codec

      Codec<V> codec()
    • get

      V get(T object)
    • set

      void set(T object, V value)
    • presence

      default Predicate<T> presence()
      Returns the presence predicate for this field. If the predicate returns false, the field is skipped during encoding and decoding. Defaults to always true (field is always present).
      Returns:
      the presence predicate
    • of

      static <T, V> FieldSpec<T,V> of(String name, Codec<V> codec, Function<T,V> getter, BiConsumer<T,V> setter)
      Creates a FieldSpec from explicit getter and setter functions.
      Type Parameters:
      T - the object type
      V - the field value type
      Parameters:
      name - the field name
      codec - the codec for the field value
      getter - function to extract the field value
      setter - consumer to set the field value
      Returns:
      a new FieldSpec
    • of

      static <T, V> FieldSpec<T,V> of(String name, Codec<V> codec, Function<T,V> getter, BiConsumer<T,V> setter, Predicate<T> presence)
      Creates a FieldSpec from explicit getter, setter, and presence predicate.
      Type Parameters:
      T - the object type
      V - the field value type
      Parameters:
      name - the field name
      codec - the codec for the field value
      getter - function to extract the field value
      setter - consumer to set the field value
      presence - predicate to determine if field is present
      Returns:
      a new FieldSpec