DataStax Academy FAQ

DataStax Academy migrated to a new learning management system (LMS) in July 2020. We are also moving to a new Cassandra Certification process so there are changes to exam bookings, voucher system and issuing of certificates.

Check out the Academy FAQ pages for answers to your questions:


question

Ryan Quey avatar image
Ryan Quey asked ·

Is there a simple way to add a custom codec in Java driver 4.6?

I want to write a custom codec for one of my UDTs. Is there a simple way to do this with Java Driver 4.6, without having to write out an entire codec? I found this solution that seems quite simple and intuitive, but it refers to a class MappingManager that does not seem to exist in 4.6 as far as I can tell. It seems to have been done away with starting in v4.1.

driverjavacodecmappingudt
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

alexandre.dutra avatar image
alexandre.dutra answered ·

The class MappingManager is indeed from a legacy version of the driver, don't try to use it, the example you were referring to is old.

With driver 4+, if you are using the object mapper, then UDTs are mapped for you for free, all you have to do is annotate your class with @Entity. See the mapper documentation on entities.

If you are not using the object mapper though, then you need to create a codec for your Java class. The easiest way is to extend MappingCodec, as explained here. It's usually trivial.

2 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Thanks for the answer, just wanted to add that the docs for `MappingCodec` can be found here (thanks to @smadhavan for that link)

0 Likes 0 · ·

@Ryan Quey, GTK!

0 Likes 0 · ·
smadhavan avatar image
smadhavan answered ·

@Ryan Quey, Custom Codecs can be implemented by following this documentation of DataStax Java Driver 4.6 series. You can also find an example implementation at this repo at DataStax-Examples.

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.