org.javers.core.json.JsonTypeAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javers-core Show documentation
Show all versions of javers-core Show documentation
JaVers - object auditing and diff framework for Java
package org.javers.core.json;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
import com.google.gson.JsonSerializationContext;
import org.javers.core.metamodel.type.CustomType;
import org.javers.core.metamodel.type.ValueType;
import java.util.List;
/**
* Javers abstraction over native
* Gson TypeAdapter.
*
*
* Implement JsonTypeAdapter to add custom JSON serialization and deserialization behaviour,
* depending on your domain model.
*
*
* {@link ValueType} or {@link 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 {@link org.javers.core.json.typeadapter.util.LocalDateTimeTypeAdapter}.
*
*
* @param user type, mapped to {@link ValueType} or {@link CustomType}
* @see JsonConverter
* @author bartosz walacik
*/
public interface JsonTypeAdapter {
/**
* @param json not null and not JsonNull
* @param jsonDeserializationContext use it to invoke default deserialization on the specified object
*/
T fromJson(JsonElement json, JsonDeserializationContext jsonDeserializationContext);
/**
* @param sourceValue not null
* @param jsonSerializationContext use it to invoke default serialization on the specified object
*/
JsonElement toJson(T sourceValue, JsonSerializationContext jsonSerializationContext);
/**
* 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
*/
List getValueTypes();
}