Interface JsonTypeAdapter<T>

  • Type Parameters:
    T - user type, mapped to ValueType or CustomType
    All Known Implementing Classes:
    BasicStringTypeAdapter, CdoSnapshotStateTypeAdapter, JsonTypeAdapterTemplate

    public interface JsonTypeAdapter<T>
    Javers abstraction over native Gson TypeAdapter.

    Implement JsonTypeAdapter to add custom JSON serialization and deserialization behaviour, depending on your domain model.

    ValueType or CustomType eligible for deserialization should have a no-argument constructor (public or private).

    Implementation shouldn't take care about nulls (nulls are handled by Gson engine)

    For implementation example see org.javers.core.json.typeadapter.util.LocalDateTimeTypeAdapter.

    See Also:
    JsonConverter
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      T fromJson​(com.google.gson.JsonElement json, com.google.gson.JsonDeserializationContext jsonDeserializationContext)  
      java.util.List<java.lang.Class> getValueTypes()
      Target class.
      com.google.gson.JsonElement toJson​(T sourceValue, com.google.gson.JsonSerializationContext jsonSerializationContext)  
    • Method Detail

      • fromJson

        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

        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
      • getValueTypes

        java.util.List<java.lang.Class> getValueTypes()
        Target class. If adapter is designed to handle single class, return List with one element. If adapter is polymorfic, return list captaining all supported clazz