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 Classes Modifier and Type Interface Description static interface
TypeSerializer.Annotated<V>
A type serializer that prefers type use annotation metadata to deserialize the type.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default T
deserialize(java.lang.reflect.AnnotatedType type, ConfigurationNode node)
Deserialize an object (of the correct type) from the given configuration node.T
deserialize(java.lang.reflect.Type type, ConfigurationNode node)
Deserialize an object (of the correct type) from the given configuration node.default @Nullable T
emptyValue(java.lang.reflect.AnnotatedType specificType, ConfigurationOptions options)
Create an empty value of the appropriate type.default @Nullable T
emptyValue(java.lang.reflect.Type specificType, ConfigurationOptions options)
Create an empty value of the appropriate type.static <T> ScalarSerializer<T>
of(java.lang.Class<T> type, java.util.function.BiFunction<T,java.util.function.Predicate<java.lang.Class<?>>,java.lang.Object> serializer, CheckedFunction<java.lang.Object,T,SerializationException> deserializer)
Given the provided functions, create a new serializer for a scalar value.static <T> ScalarSerializer<T>
of(java.lang.reflect.Type type, java.util.function.BiFunction<T,java.util.function.Predicate<java.lang.Class<?>>,java.lang.Object> serializer, CheckedFunction<java.lang.Object,T,SerializationException> deserializer)
Given the provided functions, create a new serializer for a scalar value.default void
serialize(java.lang.reflect.AnnotatedType type, @Nullable T obj, ConfigurationNode node)
Serialize an object to the given configuration node.void
serialize(java.lang.reflect.Type type, @Nullable T obj, ConfigurationNode node)
Serialize an object to the given configuration node.
-
-
-
Method Detail
-
of
static <T> ScalarSerializer<T> of(java.lang.reflect.Type type, java.util.function.BiFunction<T,java.util.function.Predicate<java.lang.Class<?>>,java.lang.Object> serializer, CheckedFunction<java.lang.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(java.lang.Class<T> type, java.util.function.BiFunction<T,java.util.function.Predicate<java.lang.Class<?>>,java.lang.Object> serializer, CheckedFunction<java.lang.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
default T deserialize(java.lang.reflect.AnnotatedType type, ConfigurationNode node) throws SerializationException
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
T deserialize(java.lang.reflect.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
default void serialize(java.lang.reflect.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
void serialize(java.lang.reflect.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(java.lang.reflect.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
-
emptyValue
default @Nullable T emptyValue(java.lang.reflect.AnnotatedType 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 annotated subtype to create an empty value ofoptions
- options used from the loading node- Returns:
- new empty value
- Since:
- 4.2.0
-
-