public class SerializationContext
extends java.lang.Object
NBTSerializer
or NBTDeserializer
can and should delegate
serialization of complex types to this context that will find the appropriate NBTSerializer
or NBTDeserializer
for the job. Each should only be responsible for the name of the
key that the complex type is at and the primitive fields (including strings and lists of primitives).Modifier and Type | Method and Description |
---|---|
boolean |
canDeserialize(java.lang.Class type)
Check if this context is able to deserialize the given type.
|
boolean |
canSerialize(java.lang.Class type)
Check if this context is able to serialize the given type.
|
<T> T |
deserialize(NBTBaseTag tag,
java.lang.Class<T> type)
Deserialize the tag into an object of the given type.
|
TagFactory |
factory()
Obtain the tag factory used in serialization and deserialization.
|
NBTBaseTag |
serialize(java.lang.Object data)
Serialize the given data as an NBTBaseTag.
|
<T,S extends T> |
serialize(S data,
java.lang.Class<T> type)
Serialize the given data as an
NBTBaseTag |
public <T> T deserialize(NBTBaseTag tag, java.lang.Class<T> type)
T
- the type of the object represented by the serialized tagtag
- the raw data tagtype
- the class of the serialized objectNBTDeserializationException
- if a deserializer cannot be found for the given type or
the deserializer throws an exception.public NBTBaseTag serialize(java.lang.Object data)
data
- the data to serializeNBTSerializationException
- if a serializer for the class of the data cannot be found
or an exception is raised during serialization.public <T,S extends T> NBTBaseTag serialize(S data, java.lang.Class<T> type)
NBTBaseTag
T
- the type of the serializing data, think of this as the type
to down cast toS
- the type of the data, it must be T or a sub class of Tdata
- the data to serializetype
- the class that the serializer is able to serializeNBTSerializationException
- if a serializer for the given type is not found or
an exception is raised during serialization.public boolean canDeserialize(java.lang.Class type)
type
- the class of the object to deserializetype
, false otherwise.public boolean canSerialize(java.lang.Class type)
type
- the class of the object to serializetype
, false otherwise.public TagFactory factory()
NBTSerializer
s and NBTDeserializer
s
as the context is always passed with a serialization or deserialization request.TagFactory
for wrapping and instantiating tags.