Class GenericNbtAdapter
java.lang.Object
net.xun.lib.common.api.nbt.adapters.GenericNbtAdapter
- All Implemented Interfaces:
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:
NbtUtils.writeField(Object)for serializationNbtUtils.readField(Tag)for deserialization
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSpecifiesObjectas the fallback target type, ensuring this adapter is used only when no type-specific adapters are available.load(net.minecraft.nbt.Tag tag) Deserializes objects usingNbtUtils's reflection-based approach.net.minecraft.nbt.TagSerializes objects usingNbtUtils's reflection-based approach.
-
Constructor Details
-
GenericNbtAdapter
public GenericNbtAdapter()
-
-
Method Details
-
getTargetType
SpecifiesObjectas the fallback target type, ensuring this adapter is used only when no type-specific adapters are available.- Specified by:
getTargetTypein interfaceINbtAdapter<Object>
-
save
Serializes objects usingNbtUtils's reflection-based approach.- Specified by:
savein interfaceINbtAdapter<Object>- Parameters:
value- Non-null object to serialize. Must be of a type recognized byNbtUtils- Returns:
- Non-null NBT representation. Actual tag type depends on object structure
- Throws:
IllegalArgumentException- IfNbtUtilscannot serialize the object
-
load
Deserializes objects usingNbtUtils's reflection-based approach.- Specified by:
loadin interfaceINbtAdapter<Object>- Parameters:
tag- Non-null NBT data created bysave(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
-