arangodb/java-velocypack

Allow use of type tokens in `VPackDeserializationContext` for deserializing generic Lists

rocketraman opened this issue · 3 comments

The VPackDeserializationContext currently takes a Class<T> as a parameter. The underlying code does not require a Class<T>, it only requires the more general Type.

By accepting a Type in the VPackDeserializationContext.deserialize interface method rather than Class<T>, the user is free to pass in other implementations of Type, such as ParameterizedType which can be used to deserialize Lists with a parameterized type, as well as Maps). These parameters can be generated and "reified" by using a "type token" implementation, such as is provided in Guava, and indeed in quite a few other libraries as well.

Along with some minor additional code in VPack.java to deal with deserializing wildcard types e.g. if we try to deserialize into a list like List<? extends Foo> this works quite well.

This does also require a minor change in a couple of places in the java driver to cast the result coming back from this call, because java's type inference sucks. I suppose for the same reason this is also a backward incompatible change, and so this probably requires a major version bump. However, I've left the versions alone for now.

@rocketraman thanks a lot for you contribution. We are using a Apache 2 CLA for ArangoDB and related projects, which can be found here: https://www.arangodb.com/documents/cla.pdf

We have not been able to set of an electronic system yet. Can you sign, scan and email it to cla (at) arangodb.com?

Thanks a lot
Mark

Thanks a lot for your contribution. I merged your PR