Class ScalarSerializer<T>
java.lang.Object
org.spongepowered.configurate.serialize.ScalarSerializer<T>
- Type Parameters:
- T- the object type to serialize
- All Implemented Interfaces:
- TypeSerializer<T>,- TypeSerializer.Annotated<T>
- Direct Known Subclasses:
- ScalarSerializer.Annotated
Serialize a value that can be represented as a scalar value within a node.
 Implementations must be able to serialize when one of the accepted types is
 a 
String, and may support any other types as desired.
 When serializing to a node, null values will be passed through directly. If the type serialized by this serializer is one of the native types of the backing node, it will be written directly to the node without any transformation.
Any serialized value must be deserializable by the same serializer.
- Since:
- 4.0.0
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classA specialization of the scalar serializer that favors annotated type methods over unannotated methods.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedScalarSerializer(io.leangen.geantyref.TypeToken<T> type) Create a new scalar serializer that handles the provided type.protectedScalarSerializer(Class<T> type) Create a new scalar serializer that handles the provided type.
- 
Method SummaryModifier and TypeMethodDescriptionfinal Tdeserialize(Object value) Attempt to deserialize the provided object using an unspecialized type.deserialize(AnnotatedType type, Object obj) Given an object of unknown type, attempt to convert it into the given type.final Tdeserialize(AnnotatedType type, ConfigurationNode node) Deserialize an object (of the correct type) from the given configuration node.abstract Tdeserialize(Type type, Object obj) Given an object of unknown type, attempt to convert it into the given type.final Tdeserialize(Type type, ConfigurationNode node) Deserialize an object (of the correct type) from the given configuration node.final voidserialize(AnnotatedType type, @Nullable T obj, ConfigurationNode node) Serialize an object to the given configuration node.protected Objectserialize(AnnotatedType type, T item, Predicate<Class<?>> typeSupported) Serialize the provided value to a supported type, testing against the provided predicate.final voidserialize(Type type, @Nullable T obj, ConfigurationNode node) Serialize an object to the given configuration node.protected abstract ObjectSerialize the provided value to a supported type, testing against the provided predicate.final StringserializeToString(T item) Serialize the item to aString, in a representation that can be interpreted by this serializer again.final @Nullable TtryDeserialize(@Nullable Object obj) Attempt to deserialize the provided object, but rather than throwing an exception when a deserialization error occurs, return null instead.final io.leangen.geantyref.TypeToken<T>type()Get the general type token applicable for this serializer.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.spongepowered.configurate.serialize.TypeSerializer.AnnotatedemptyValue, emptyValue
- 
Constructor Details- 
ScalarSerializerCreate a new scalar serializer that handles the provided type.- Parameters:
- type- type to handle
- Since:
- 4.0.0
 
- 
ScalarSerializerCreate a new scalar serializer that handles the provided type.typemust not be a raw parameterized type.- Parameters:
- type- type to handle
- Since:
- 4.0.0
 
 
- 
- 
Method Details- 
typeGet the general type token applicable for this serializer. This token may be parameterized.- Returns:
- the type token for this serializer
- Since:
- 4.0.0
 
- 
deserializeDescription copied from interface:TypeSerializerDeserialize an object (of the correct type) from the given configuration node.- Specified by:
- deserializein interface- TypeSerializer<T>
- Specified by:
- deserializein interface- TypeSerializer.Annotated<T>
- Parameters:
- type- the type of return value required
- node- the node containing serialized data
- Returns:
- an object
- Throws:
- SerializationException- if the presented data is invalid
 
- 
deserializepublic final T deserialize(AnnotatedType type, ConfigurationNode node) throws SerializationException Description copied from interface:TypeSerializerDeserialize an object (of the correct type) from the given configuration node.- Specified by:
- deserializein interface- TypeSerializer<T>
- Specified by:
- deserializein interface- TypeSerializer.Annotated<T>
- Parameters:
- type- the annotated type of return value required
- node- the node containing serialized data
- Returns:
- an object
- Throws:
- SerializationException- if the presented data is invalid
 
- 
deserializeAttempt to deserialize the provided object using an unspecialized type. This may fail on more complicated deserialization processes such as with enum types.- Parameters:
- value- the object to deserialize.
- Returns:
- the deserialized object, if possible
- Throws:
- SerializationException- if unable to coerce the value to the requested type.
- Since:
- 4.0.0
 
- 
deserializeGiven an object of unknown type, attempt to convert it into the given type.- Parameters:
- type- the specific type of the type's usage
- obj- the object to convert
- Returns:
- a converted object
- Throws:
- SerializationException- if the object could not be converted for any reason
- Since:
- 4.2.0
 
- 
deserializeGiven an object of unknown type, attempt to convert it into the given type.- Parameters:
- type- the specific type of the type's usage
- obj- the object to convert
- Returns:
- a converted object
- Throws:
- SerializationException- if the object could not be converted for any reason
- Since:
- 4.0.0
 
- 
serializeDescription copied from interface:TypeSerializerSerialize an object to the given configuration node.- Specified by:
- serializein interface- TypeSerializer<T>
- Specified by:
- serializein interface- TypeSerializer.Annotated<T>
- Parameters:
- type- the annotated type of the input object
- obj- the object to be serialized
- node- the node to write to
 
- 
serializeDescription copied from interface:TypeSerializerSerialize an object to the given configuration node.- Specified by:
- serializein interface- TypeSerializer<T>
- Specified by:
- serializein interface- TypeSerializer.Annotated<T>
- Parameters:
- type- the type of the input object
- obj- the object to be serialized
- node- the node to write to
 
- 
serializeSerialize the provided value to a supported type, testing against the provided predicate.Annotated type information is provided for reference. - Parameters:
- type- the annotated type of the field being serialized
- item- the value to serialize
- typeSupported- a predicate to allow choosing which types are supported
- Returns:
- a serialized form of this object
- Since:
- 4.2.0
 
- 
serializeSerialize the provided value to a supported type, testing against the provided predicate.- Parameters:
- item- the value to serialize
- typeSupported- a predicate to allow choosing which types are supported
- Returns:
- a serialized form of this object
- Since:
- 4.0.0
 
- 
tryDeserializeAttempt to deserialize the provided object, but rather than throwing an exception when a deserialization error occurs, return null instead.- Parameters:
- obj- the object to try to deserialize
- Returns:
- an instance of the appropriate type, or null
- Since:
- 4.0.0
- See Also:
 
- 
serializeToStringSerialize the item to aString, in a representation that can be interpreted by this serializer again.- Parameters:
- item- the item to serialize
- Returns:
- the serialized form of the item
- Since:
- 4.0.0
 
 
-