Allow user to register custom type codecs

Description

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>>

Environment

None

Pull Requests

None

Activity

Alex Dutra July 23, 2015 at 11:13 AM

The PR is now stable. Please read the following documents for information about the current state of code:

README file:
https://github.com/datastax/java-driver/blob/java721-2.2/features/custom_codecs/README.md

Upgrade Guide (with summary of API breaking changes):
https://github.com/datastax/java-driver/blob/java721-2.2/upgrade_guide/README.md

Fixed

Details

Assignee

Reporter

Fix versions

Priority

Created April 23, 2015 at 1:17 PM
Updated July 30, 2015 at 12:04 PM
Resolved July 24, 2015 at 9:06 PM