Class GenericNbtAdapter

java.lang.Object
net.xun.lib.common.api.nbt.adapters.GenericNbtAdapter
All Implemented Interfaces:
INbtAdapter<Object>

public class GenericNbtAdapter extends Object implements INbtAdapter<Object>
Default NBT adapter handling serialization through reflection-based NbtUtils methods.

Serves as the ultimate fallback in the adapter resolution chain, processing any type not explicitly handled by a registered INbtAdapter. This implementation delegates to:

Capable of handling all types supported by NbtUtils's reflection-based system, including primitives, collections, and arrays. For complex object graphs or types requiring special handling (e.g., custom data validation), implement a dedicated INbtAdapter.

See Also:
  • Constructor Details

    • GenericNbtAdapter

      public GenericNbtAdapter()
  • Method Details

    • getTargetType

      public Class<Object> getTargetType()
      Specifies Object as the fallback target type, ensuring this adapter is used only when no type-specific adapters are available.
      Specified by:
      getTargetType in interface INbtAdapter<Object>
    • save

      public net.minecraft.nbt.Tag save(Object value)
      Serializes objects using NbtUtils's reflection-based approach.
      Specified by:
      save in interface INbtAdapter<Object>
      Parameters:
      value - Non-null object to serialize. Must be of a type recognized by NbtUtils
      Returns:
      Non-null NBT representation. Actual tag type depends on object structure
      Throws:
      IllegalArgumentException - If NbtUtils cannot serialize the object
    • load

      public Object load(net.minecraft.nbt.Tag tag)
      Deserializes objects using NbtUtils's reflection-based approach.
      Specified by:
      load in interface INbtAdapter<Object>
      Parameters:
      tag - Non-null NBT data created by save(Object)
      Returns:
      Deserialized object instance, or null if the original serialized value was null
      Throws:
      ClassCastException - If the tag type doesn't match the expected format for the target Java type