Package io.bytestreams.codec.core
Interface FieldSpec<T,V>
- Type Parameters:
T- the object type containing this fieldV- 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 TypeMethodDescriptioncodec()name()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.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.presence()Returns the presence predicate for this field.void
-
Method Details
-
name
String name() -
codec
-
get
-
set
-
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 typeV- the field value type- Parameters:
name- the field namecodec- the codec for the field valuegetter- function to extract the field valuesetter- 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 typeV- the field value type- Parameters:
name- the field namecodec- the codec for the field valuegetter- function to extract the field valuesetter- consumer to set the field valuepresence- predicate to determine if field is present- Returns:
- a new FieldSpec
-