@Override
        public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
            Class<T> rawType = (Class<T>) type.getRawType();
            if (rawType != Optional.class) {
                return null;
            }
            if (type.getType() instanceof ParameterizedType) {
                final ParameterizedType parameterizedType = (ParameterizedType) type.getType();
                final Type actualType = parameterizedType.getActualTypeArguments()[0];
                final TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(actualType));
                return new OptionalTypeAdapter(adapter);
            } else {
                final TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(Object.class));
                return new OptionalTypeAdapter(adapter);
            }
        }
use in GsonBuilder
instance.registerTypeAdapterFactory(OptionalTypeAdapter.FACTORY)

@author davey
@param <E>
fluent-mybatis-annotation/src/main/java/cn/org/atool/fluent/common/kits/gson/OptionalTypeAdapter.java