org.javers.java8support.OptionalTypeAdapter 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.java8support;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.reflect.TypeToken;
import org.javers.common.reflection.ReflectionUtil;
import org.javers.core.json.JsonAdvancedTypeAdapter;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Optional;
public class OptionalTypeAdapter implements JsonAdvancedTypeAdapter {
@Override
public Optional fromJson(JsonElement json, Type typeOfT, JsonDeserializationContext jsonDeserializationContext) {
if ( json.isJsonObject() ) {
JsonObject jsonObject = (JsonObject)json;
List elementTypes = ReflectionUtil.getAllTypeArguments(typeOfT);
Type elementType = null;
if (elementTypes.size() == 0) {
elementType = new TypeToken