Class GsonObjectSerializer

java.lang.Object
com.reallifedeveloper.common.infrastructure.GsonObjectSerializer
All Implemented Interfaces:
ObjectSerializer<String>

public class GsonObjectSerializer extends Object implements ObjectSerializer<String>
An implementation of the ObjectSerializer that uses JSON as the serialized form.
Author:
RealLifeDeveloper
  • Field Details

    • DATE_FORMAT

      public static final String DATE_FORMAT
      The format used to parse and format date objects. The string is a pattern that can be used by a java.time.DateTimeFormatter.
      See Also:
    • LOCAL_DATE_TIME_FORMAT

      public static final String LOCAL_DATE_TIME_FORMAT
      The format used to parse and format java.time.LocalDateTime objects. The string is a pattern that can be used by a DateTimeFormatter.
      See Also:
    • DATE_TIME_FORMAT

      public static final String DATE_TIME_FORMAT
      The format used to parse and format java.time.ZonedDateTime objects. The string is a pattern that can be used by a DateTimeFormatter.
      See Also:
  • Constructor Details

    • GsonObjectSerializer

      public GsonObjectSerializer()
      Creates a new GsonObjectSerializer with default values.

      The default values include using the pattern "yyyy-MM-dd\'T\'HH:mm:ss.SSSX" when working with java.time.ZonedDateTime objects.

  • Method Details

    • serialize

      public String serialize(Object object)
      Description copied from interface: ObjectSerializer
      Converts an object to its serialized form.

      The implementation should support serializing null values.

      Specified by:
      serialize in interface ObjectSerializer<String>
      Parameters:
      object - the object to serialize, can be null
      Returns:
      the serialized representation of object
    • deserialize

      public <U> U deserialize(String serializedObject, Class<U> objectType)
      Description copied from interface: ObjectSerializer
      Given the serialized representation of an object, converts it back to the object.
      Specified by:
      deserialize in interface ObjectSerializer<String>
      Type Parameters:
      U - the type of the object
      Parameters:
      serializedObject - the serialized form of an object
      objectType - the concrete class of the serialized object
      Returns:
      the object represented by serializedObject