All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.javers.core.json.JsonTypeAdapter Maven / Gradle / Ivy

There is a newer version: 7.6.1
Show newest version
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(); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy