Interface TypeSerializer<T>
-
- Type Parameters:
T
- the type
- All Known Implementing Classes:
ScalarSerializer
public interface TypeSerializer<T>
Represents an object which can serialize and deserialize objects of a given type.- Since:
- 4.0.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description T
deserialize(Type type, ConfigurationNode node)
Deserialize an object (of the correct type) from the given configuration node.default @Nullable T
emptyValue(Type specificType, ConfigurationOptions options)
Create an empty value of the appropriate type.static <T> ScalarSerializer<T>
of(Class<T> type, BiFunction<T,Predicate<Class<?>>,Object> serializer, CheckedFunction<Object,T,SerializationException> deserializer)
Given the provided functions, create a new serializer for a scalar value.static <T> ScalarSerializer<T>
of(Type type, BiFunction<T,Predicate<Class<?>>,Object> serializer, CheckedFunction<Object,T,SerializationException> deserializer)
Given the provided functions, create a new serializer for a scalar value.void
serialize(Type type, @Nullable T obj, ConfigurationNode node)
Serialize an object to the given configuration node.
-
-
-
Method Detail
-
of
static <T> ScalarSerializer<T> of(Type type, BiFunction<T,Predicate<Class<?>>,Object> serializer, CheckedFunction<Object,T,SerializationException> deserializer)
Given the provided functions, create a new serializer for a scalar value.The returned serializer must fulfill all the requirements of a
ScalarSerializer
- Type Parameters:
T
- the type of value to deserialize- Parameters:
type
- the type of value returned by the serializerserializer
- the serialization function, implementingScalarSerializer.serialize(Object, Predicate)
deserializer
- the deserialization function, implementingScalarSerializer.deserialize(Type, Object)
- Returns:
- a new and unregistered type serializer
- Since:
- 4.0.0
-
of
static <T> ScalarSerializer<T> of(Class<T> type, BiFunction<T,Predicate<Class<?>>,Object> serializer, CheckedFunction<Object,T,SerializationException> deserializer)
Given the provided functions, create a new serializer for a scalar value.The returned serializer must fulfill all the requirements of a
ScalarSerializer
- Type Parameters:
T
- the type of value to deserialize- Parameters:
type
- the type of value. Must not be a parameterized typeserializer
- the serialization function, implementingScalarSerializer.serialize(Object, Predicate)
deserializer
- the deserialization function, implementingScalarSerializer.deserialize(Type, Object)
- Returns:
- a new and unregistered type serializer
- Since:
- 4.0.0
- See Also:
for the version of this function that takes a parameterized type
-
deserialize
T deserialize(Type type, ConfigurationNode node) throws SerializationException
Deserialize an object (of the correct type) from the given configuration node.- Parameters:
type
- the type of return value requirednode
- the node containing serialized data- Returns:
- an object
- Throws:
SerializationException
- if the presented data is invalid- Since:
- 4.0.0
-
serialize
void serialize(Type type, @Nullable T obj, ConfigurationNode node) throws SerializationException
Serialize an object to the given configuration node.- Parameters:
type
- the type of the input objectobj
- the object to be serializednode
- the node to write to- Throws:
SerializationException
- if the object cannot be serialized- Since:
- 4.0.0
-
emptyValue
default @Nullable T emptyValue(Type specificType, ConfigurationOptions options)
Create an empty value of the appropriate type.This method is for the most part designed to create empty collection types, though it may be useful for scalars in limited cases.
- Parameters:
specificType
- specific subtype to create an empty value ofoptions
- options used from the loading node- Returns:
- new empty value
- Since:
- 4.0.0
-
-