Class BasicStringTypeAdapter<T>

java.lang.Object
org.javers.core.json.JsonTypeAdapterTemplate<T>
org.javers.core.json.BasicStringTypeAdapter<T>
All Implemented Interfaces:
AbstractJsonTypeAdapter, 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.

  • Constructor Details

    • BasicStringTypeAdapter

      public BasicStringTypeAdapter()
  • Method Details

    • serialize

      public abstract 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(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