Package io.ran

Class GsonSerializer

java.lang.Object
io.ran.GsonSerializer
All Implemented Interfaces:
ISerializer

public class GsonSerializer extends Object implements ISerializer
A generic Gson based serializer to be used with Serialized annotation on model fields.
  • Constructor Details

    • GsonSerializer

      public GsonSerializer()
  • Method Details

    • deserialize

      public <T> T deserialize(Class<T> clazz, String value)
      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 a Clazz 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 interface ISerializer
      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

      public <T> T deserialize(Clazz<T> clazz, String value)
      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 Java Class.

      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 interface ISerializer
      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

      public <T> String serialize(T object)
      Description copied from interface: ISerializer
      Serialize an object into a string.
      Specified by:
      serialize in interface ISerializer
      Type Parameters:
      T - The type of the object to serialize.
      Parameters:
      object - The object to serialize.
      Returns:
      A string representation of the given object.