Interface JsonTypeAdapter<T>

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

public interface JsonTypeAdapter<T> extends AbstractJsonTypeAdapter
JsonTypeAdapter allows to customize JSON serialization of your ValueType or CustomType in a JaversRepository.

Implementation shouldn't take care about nulls (nulls are handled by Gson engine). For a concrete adapter implementation example see LocalDateTimeTypeAdapter.

Convenient template classes are available, see BasicStringTypeAdapter

Usage with Vanilla Javers

Javers javers = JaversBuilder.javers()
                  .registerValueTypeAdapter(new MyTypeAdapter())
                  .build();
 
Usage with Javers Spring Boot starters
Simply register your JSON type adapters as Spring beans.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    fromJson(com.google.gson.JsonElement json, com.google.gson.JsonDeserializationContext jsonDeserializationContext)
     
    Target class (or classes), typically ValueType or CustomType.
    com.google.gson.JsonElement
    toJson(T sourceValue, com.google.gson.JsonSerializationContext jsonSerializationContext)
     
  • Method Details

    • 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

      List<Class> getValueTypes()
      Target class (or classes), typically ValueType or CustomType.
      Each target class should have a no-argument constructor (public or private).

      If adapter is designed to handle single class, should return a List with one element — a supported class.
      If adapter is polymorphic, should return all supported classes.