Interface TypeSerializer<T>
- Type Parameters:
T
- the type
- All Known Subinterfaces:
TypeSerializer.Annotated<V>
- All Known Implementing Classes:
AbstractListChildSerializer
,ScalarSerializer
,ScalarSerializer.Annotated
public interface TypeSerializer<T>
Represents an object which can serialize and deserialize objects of a
given type.
The type serializer interface has methods both for working with
annotated types, and discarding annotated type information. If annotation
information is desired, the TypeSerializer.Annotated
interface overrides the
standard TypeSerializer interface to prefer annotated type information.
- Since:
- 4.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
A type serializer that prefers type use annotation metadata to deserialize the type. -
Method Summary
Modifier and TypeMethodDescriptiondefault T
deserialize
(AnnotatedType type, ConfigurationNode node) Deserialize an object (of the correct type) from the given configuration node.deserialize
(Type type, ConfigurationNode node) Deserialize an object (of the correct type) from the given configuration node.default @Nullable T
emptyValue
(AnnotatedType specificType, ConfigurationOptions options) Create an empty value of the appropriate type.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.default void
serialize
(AnnotatedType type, @Nullable T obj, ConfigurationNode node) Serialize an object to the given configuration node.void
serialize
(Type type, @Nullable T obj, ConfigurationNode node) Serialize an object to the given configuration node.
-
Method Details
-
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:
-
deserialize
Deserialize an object (of the correct type) from the given configuration node.- Parameters:
type
- the annotated type of return value requirednode
- the node containing serialized data- Returns:
- an object
- Throws:
SerializationException
- if the presented data is invalid- Since:
- 4.2.0
-
deserialize
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
default void serialize(AnnotatedType type, @Nullable T obj, ConfigurationNode node) throws SerializationException Serialize an object to the given configuration node.- Parameters:
type
- the annotated 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.2.0
-
serialize
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
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
-
emptyValue
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 annotated subtype to create an empty value ofoptions
- options used from the loading node- Returns:
- new empty value
- Since:
- 4.2.0
-