public class StandardSerializer extends Object implements YamlSerializer
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_SERIALIZED_TYPE_KEY
Default key for serialized class identifier.
|
| Constructor and Description |
|---|
StandardSerializer(Object serializedTypeKey)
Creates a serializer.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
deserialize(Map<Object,Object> map)
Attempts to deserialize the given map into a class instance using this serializer.
|
static StandardSerializer |
getDefault()
Returns the default serializer, which uses
DEFAULT_SERIALIZED_TYPE_KEY. |
Set<Class<?>> |
getSupportedClasses()
Returns a set of all explicitly defined classes this serializer supports and can (de-)serialize.
|
Set<Class<?>> |
getSupportedParentClasses()
Returns a set of all parent classes (classes, interfaces...) instances of which this serializer supports and can
(de-)serialize.
|
<T> void |
register(Class<T> clazz,
TypeAdapter<T> adapter)
Registers the given type for serialization.
|
<T> void |
register(String alias,
Class<T> clazz)
Registers the specified alias for the given type (represented by the class).
|
<T> Map<Object,Object> |
serialize(T object,
MapSupplier supplier)
Attempts to serialize the given object into a map and returns it.
|
public static final String DEFAULT_SERIALIZED_TYPE_KEY
defaultSerializer.public StandardSerializer(@NotNull
Object serializedTypeKey)
serializedTypeKey - the key for serialized class identifierpublic <T> void register(@NotNull
Class<T> clazz,
@NotNull
TypeAdapter<T> adapter)
me.name.project.objects.Custom).
If you also want to set an alias (maybe for compatibility reasons), please use register(String, Class)
afterwards.
T - type to registerclazz - the class of the type to registeradapter - adapter for the typepublic <T> void register(@NotNull
String alias,
@NotNull
Class<T> clazz)
The type must already be registered.
T - type to registerclazz - the class to registeralias - alias for the class to register@Nullable public Object deserialize(@NotNull Map<Object,Object> map)
YamlSerializer
The given map is a raw object map - there are no Block instances, just the values themselves.
If the serializer does not recognize the map, or could not deserialize the map, this method must return
null.
deserialize in interface YamlSerializermap - the raw map to deserialize@Nullable public <T> Map<Object,Object> serialize(@NotNull T object, @NotNull MapSupplier supplier)
YamlSerializerThe given object is guaranteed to be:
YamlSerializer.getSupportedClasses(),YamlSerializer.getSupportedParentClasses().GeneralSettings.getDefaultMapSupplier().
Serializers should not use their own map implementations, they should return the map provided by the supplier.
If could not serialize into a map, this method must return null.
serialize in interface YamlSerializerT - type of the object to serializeobject - the object to serializesupplier - the supplier used to supply default maps@NotNull public Set<Class<?>> getSupportedClasses()
YamlSerializer
The returned set cannot be null as indicated by the annotation.
getSupportedClasses in interface YamlSerializer@NotNull public Set<Class<?>> getSupportedParentClasses()
YamlSerializer
The returned set cannot be null as indicated by the annotation.
getSupportedParentClasses in interface YamlSerializerpublic static StandardSerializer getDefault()
DEFAULT_SERIALIZED_TYPE_KEY.Copyright © 2022. All rights reserved.