@Override
    public Optional<E> read(JsonReader in) throws IOException {
        if (in.peek() != JsonToken.NULL) {
            return Optional.ofNullable(adapter.read(in));
        } else {
            in.nextNull();
            return Optional.empty();
        }
    }
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