Class RecordField<O,T>
java.lang.Object
com.github.darksoulq.abyssallib.common.serialization.RecordField<O,T>
- Type Parameters:
O- The parent object type.T- The type of the field's value.
Represents a fully bound field within a structured record codec.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<D> DataResult<T> decodeFromMap(DynamicOps<D> ops, Map<D, D> map) Safely executes decoding logic against a provided map structure.<D> DataResult<D> encodeToMap(DynamicOps<D> ops, O value) Safely triggers encoding logic isolating the field from the parent object.getCodec()getName()boolean
-
Constructor Details
-
RecordField
public RecordField(String name, List<String> aliases, Codec<T> codec, Function<O, T> getter, boolean optional, T defaultValue) Constructs the finalized record mapping.- Parameters:
name- The structural identifier for the field map key.aliases- Legacy identification alternatives fallback map mapping nodes safely structurally defining targets.codec- The target codec resolving the data.getter- The extraction function routing data from the parent instance.optional- Whether the field's absence should be tolerated.defaultValue- The fallback primitive value to utilize if missing.
-
-
Method Details
-
getName
- Returns:
- The structural identifier for this field.
-
getCodec
-
isOptional
public boolean isOptional()- Returns:
- Whether the field's absence should be tolerated.
-
getDefaultValue
- Returns:
- The fallback value utilized if the field is missing.
-
decodeFromMap
Safely executes decoding logic against a provided map structure. Handles missing key mitigation logic natively.- Type Parameters:
D- The underlying data format wrapper.- Parameters:
ops- The dynamic operations layer.map- The map structure being targeted for decoding.- Returns:
- A DataResult detailing success or decoding failure.
-
encodeToMap
Safely triggers encoding logic isolating the field from the parent object.- Type Parameters:
D- The underlying data format wrapper.- Parameters:
ops- The dynamic operations layer.value- The parent instance containing the target field.- Returns:
- A DataResult containing the encoded node.
-