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 Summary

    Modifier and Type
    Method
    Description
     
    get(T object)
     
     
    static <T,V> FieldSpec<T,V>
    of(String name, Codec<V> codec, Function<? super T, V> getter, BiConsumer<? super T, V> setter)
    Creates a FieldSpec from explicit getter and setter functions.
    static <T,V> FieldSpec<T,V>
    of(String name, Codec<V> codec, Function<? super T, V> getter, BiConsumer<? super T, V> setter, Predicate<? super T> presence)
    Creates a FieldSpec from explicit getter, setter, and presence predicate.
    default Predicate<T>
    Returns the presence predicate for this field.
    void
    set(T object, V value)
     
  • 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<? super T, V> getter, BiConsumer<? super T, V> setter)
      Creates a FieldSpec from explicit getter and setter functions.

      The getter and setter may be declared on a supertype of T.

      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<? super T, V> getter, BiConsumer<? super T, V> setter, Predicate<? super T> presence)
      Creates a FieldSpec from explicit getter, setter, and presence predicate.

      The getter, setter and presence predicate may be declared on a supertype of T.

      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