A common request is to support deserialization of query results to other types (e.g. dates as JDK 8 dates). Currently users can call getBytesUnsafe and add their logic in a separate utility method, but it would be more convenient if this was integrated in the API.
We could expose the TypeCodec type and allow custom implementations to be registered with the cluster:
Then we would have new getters on GettableData. I can see the case where multiple custom codecs would have the same target type, so it's probably best to pass the codec class as a type token:
Some experimentation is still needed to sort out the details:
does the API above work with generic result types?
how do we deal with the protocol version on the 2.1 branch?
what about variable binding? (in particular for simple statements, where the type of the target column is unknown)
handling collections, i.e. make List<T> work when only a Codec<T> is provided, not a Codec<List<T>>
Final decision:
Please refer to the online documentation for details:
https://github.com/datastax/java-driver/blob/2.2/features/custom_codecs/README.md
Initial ticket description:
A common request is to support deserialization of query results to other types (e.g. dates as JDK 8 dates). Currently users can call
getBytesUnsafe
and add their logic in a separate utility method, but it would be more convenient if this was integrated in the API.We could expose the
TypeCodec
type and allow custom implementations to be registered with the cluster:Then we would have new getters on
GettableData
. I can see the case where multiple custom codecs would have the same target type, so it's probably best to pass the codec class as a type token:Some experimentation is still needed to sort out the details:
does the API above work with generic result types?
how do we deal with the protocol version on the 2.1 branch?
what about variable binding? (in particular for simple statements, where the type of the target column is unknown)
handling collections, i.e. make List<T> work when only a Codec<T> is provided, not a Codec<List<T>>