Class V9DateTimeJsonAdapter

  • All Implemented Interfaces:
    com.google.gson.JsonDeserializer<java.time.OffsetDateTime>, com.google.gson.JsonSerializer<java.time.OffsetDateTime>

    public class V9DateTimeJsonAdapter
    extends java.lang.Object
    implements com.google.gson.JsonSerializer<java.time.OffsetDateTime>, com.google.gson.JsonDeserializer<java.time.OffsetDateTime>
    Adapter for serializing and deserializing OffsetDateTime to and from JSON in a format compatible with the legacy XMLGregorianCalendar used in older versions of the library.

    This adapter is used to maintain backward compatibility with systems that expect the older date-time format while allowing migration to Java 11's OffsetDateTime.

    Serialization

    The serialize method converts an OffsetDateTime object into a JSON structure similar to the structure used by XMLGregorianCalendar, preserving the fields for year, month, day, time, timezone, and fractional seconds if present.

    Deserialization

    The deserialize method converts a JSON structure formatted for XMLGregorianCalendar into an OffsetDateTime object, parsing the legacy fields and converting them to their modern equivalents, including handling timezone and fractional seconds.
    Since:
    10.1.8
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.time.OffsetDateTime deserialize​(com.google.gson.JsonElement xMLGregorianCalendarJsonElement, java.lang.reflect.Type type, com.google.gson.JsonDeserializationContext jsonDeserializationContext)
      Deserializes a JSON element into an OffsetDateTime, converting the legacy XMLGregorianCalendar fields into their modern equivalents.
      com.google.gson.JsonElement serialize​(java.time.OffsetDateTime offsetDateTime, java.lang.reflect.Type type, com.google.gson.JsonSerializationContext jsonSerializationContext)
      Serializes an OffsetDateTime into JSON format compatible with the older XMLGregorianCalendar representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • V9DateTimeJsonAdapter

        public V9DateTimeJsonAdapter()
    • Method Detail

      • serialize

        public com.google.gson.JsonElement serialize​(java.time.OffsetDateTime offsetDateTime,
                                                     java.lang.reflect.Type type,
                                                     com.google.gson.JsonSerializationContext jsonSerializationContext)
        Serializes an OffsetDateTime into JSON format compatible with the older XMLGregorianCalendar representation.
        Specified by:
        serialize in interface com.google.gson.JsonSerializer<java.time.OffsetDateTime>
        Parameters:
        offsetDateTime - the OffsetDateTime to be serialized
        type - the specific genericized type of the source object
        jsonSerializationContext - the context for serialization
        Returns:
        a JsonElement representing the serialized date-time information
      • deserialize

        public java.time.OffsetDateTime deserialize​(com.google.gson.JsonElement xMLGregorianCalendarJsonElement,
                                                    java.lang.reflect.Type type,
                                                    com.google.gson.JsonDeserializationContext jsonDeserializationContext)
        Deserializes a JSON element into an OffsetDateTime, converting the legacy XMLGregorianCalendar fields into their modern equivalents.
        Specified by:
        deserialize in interface com.google.gson.JsonDeserializer<java.time.OffsetDateTime>
        Parameters:
        xMLGregorianCalendarJsonElement - the JSON data to be deserialized
        type - the specific genericized type of the source object
        jsonDeserializationContext - the context for deserialization
        Returns:
        the deserialized OffsetDateTime, or null if parsing fails