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.

public class RecordField<O,T> extends Object
Represents a fully bound field within a structured record codec.
  • 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

      public String getName()
      Returns:
      The structural identifier for this field.
    • getCodec

      public Codec<T> getCodec()
      Returns:
      The underlying codec responsible for resolving this field's data.
    • isOptional

      public boolean isOptional()
      Returns:
      Whether the field's absence should be tolerated.
    • getDefaultValue

      public T getDefaultValue()
      Returns:
      The fallback value utilized if the field is missing.
    • decodeFromMap

      public <D> DataResult<T> decodeFromMap(DynamicOps<D> ops, Map<D,D> map)
      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

      public <D> DataResult<D> encodeToMap(DynamicOps<D> ops, O value)
      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.