Package io.ran
Class GsonSerializer
java.lang.Object
io.ran.GsonSerializer
- All Implemented Interfaces:
ISerializer
A generic Gson based serializer to be used with
Serialized
annotation on model fields.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> T
deserialize
(Clazz<T> clazz, String value) Deserialize a string into an object of the given class.<T> T
deserialize
(Class<T> clazz, String value) Deserialize a string into an object of the given class.<T> String
serialize
(T object) Serialize an object into a string.
-
Constructor Details
-
GsonSerializer
public GsonSerializer()
-
-
Method Details
-
deserialize
Description copied from interface:ISerializer
Deserialize a string into an object of the given class.For objects with no generics, this is the same as calling
ISerializer.deserialize(Clazz, String)
with aClazz
object.For objects with generics this may not preserve the type information, and
ISerializer.deserialize(Clazz, String)
should be used instead.- Specified by:
deserialize
in interfaceISerializer
- Type Parameters:
T
- The type of the object to deserialize.- Parameters:
clazz
- The class to deserialize into.value
- The string to deserialize.- Returns:
- An instance of the given class, deserialized from the given string.
-
deserialize
Description copied from interface:ISerializer
Deserialize a string into an object of the given class.Contains a more informed
Clazz
object instead of the basic JavaClass
.By default, this delegates to the existing
ISerializer.deserialize(Class, String)
method, but can be overridden to provide more information about the class being deserialized to the deserializer.- Specified by:
deserialize
in interfaceISerializer
- Type Parameters:
T
- The type of the object to deserialize.- Parameters:
clazz
- The class to deserialize into.value
- The string to deserialize.- Returns:
- An instance of the given class, deserialized from the given string.
-
serialize
Description copied from interface:ISerializer
Serialize an object into a string.- Specified by:
serialize
in interfaceISerializer
- Type Parameters:
T
- The type of the object to serialize.- Parameters:
object
- The object to serialize.- Returns:
- A string representation of the given object.
-