Class BasicStringTypeAdapter<T>

  • All Implemented Interfaces:
    JsonTypeAdapter<T>

    public abstract class BasicStringTypeAdapter<T>
    extends JsonTypeAdapterTemplate<T>
    Convenient abstract implementation of JsonTypeAdapter. Extend it if you need to represent your ValueType as a single String.

    For a concrete adapter implementation example see LocalDateTimeTypeAdapter.

    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract T deserialize​(java.lang.String serializedValue)
      Example deserialization for LocalDateTime:
      T fromJson​(com.google.gson.JsonElement json, com.google.gson.JsonDeserializationContext jsonDeserializationContext)  
      abstract java.lang.String serialize​(T sourceValue)
      Example serialization for LocalDateTime:
      com.google.gson.JsonElement toJson​(T sourceValue, com.google.gson.JsonSerializationContext jsonSerializationContext)  
      • Methods inherited from class java.lang.Object

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

      • BasicStringTypeAdapter

        public BasicStringTypeAdapter()
    • Method Detail

      • serialize

        public abstract java.lang.String serialize​(T sourceValue)
        Example serialization for LocalDateTime:
         public String serialize(LocalDateTime sourceValue) {
             return ISO_DATE_TIME_FORMATTER.print(sourceValue);
         }
         
        Parameters:
        sourceValue - not null
      • deserialize

        public abstract T deserialize​(java.lang.String serializedValue)
        Example deserialization for LocalDateTime:
         public LocalDateTime deserialize(String serializedValue) {
             return ISO_DATE_TIME_FORMATTER.parseLocalDateTime(serializedValue);
         }
         
        Parameters:
        serializedValue - not null
      • fromJson

        public T fromJson​(com.google.gson.JsonElement json,
                          com.google.gson.JsonDeserializationContext jsonDeserializationContext)
        Parameters:
        json - not null and not JsonNull
        jsonDeserializationContext - use it to invoke default deserialization on the specified object
      • toJson

        public com.google.gson.JsonElement toJson​(T sourceValue,
                                                  com.google.gson.JsonSerializationContext jsonSerializationContext)
        Parameters:
        sourceValue - not null
        jsonSerializationContext - use it to invoke default serialization on the specified object