Class JsonConverter

java.lang.Object
org.javers.core.json.JsonConverter

public class JsonConverter extends Object
Javers is meant to support various persistence stores for any kind of client's data, hence we use JSON format to serialize/deserialize client's domain objects.

Javers uses Gson library which provides neat and pretty JSON representation for well known Java types.

But sometimes Gson's default JSON representation isn't appropriate for your domain model. This is often the case when dealing with Values like Date or Money.

If so, you can easily customize Javers serialization/deserialization behaviour by providing plugins for each of your custom type. Javers accepts several kind of plugins:
  • BasicStringTypeAdapter - extend it if you need to represent Value as single String and don't want to deal with JSON API. For concrete class example see LocalDateTimeTypeAdapter.
  • JsonTypeAdapter - use it if you need full control over JSON conversion
  • native Gson TypeAdapter
  • native Gson JsonSerializer
  • native Gson JsonDeserializer
Javers provides JsonTypeAdapters for some well known Values like java.time.LocalDateTime, java.time.LocalDateTime.
  • Method Details

    • toJson

      public String toJson(Object value)
    • toJsonElement

      public com.google.gson.JsonElement toJsonElement(Object value)
    • fromJson

      public <T> T fromJson(String json, Class<T> expectedType)
    • fromJson

      public Object fromJson(String json, Type expectedType)
    • fromJson

      public <T> T fromJson(com.google.gson.JsonElement json, Class<T> expectedType)
    • fromJsonToJsonElement

      public com.google.gson.JsonElement fromJsonToJsonElement(String json)
    • fromJson

      public <T> T fromJson(Reader reader, Type expectedType)
    • fromSerializedSnapshot

      public CdoSnapshot fromSerializedSnapshot(CdoSnapshotSerialized cdoSnapshotSerialized)