Does mapper support mapping collection of enum value?

533 views
Skip to first unread message

ziju feng

unread,
Feb 10, 2015, 8:10:32 AM2/10/15
to java-dri...@lists.datastax.com
I have a field in my entity class of type Map<SomeEnumClass,String>. I was wondering if it is currently supported by the mapper as annotating the field with @Enumerated does not work.

Thanks,

Ziju

Alex Popescu

unread,
Feb 10, 2015, 1:14:00 PM2/10/15
to java-dri...@lists.datastax.com
Ziju, 

I have found this improvement ticket https://datastax-oss.atlassian.net/browse/JAVA-605 that seems to suggest the same feature.

To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.



--

[:>-a)

Alex Popescu
Sen. Product Manager @ DataStax
@al3xandru

rHermes

unread,
Feb 15, 2015, 1:57:29 PM2/15/15
to java-dri...@lists.datastax.com
If anyone finds a way to do this, despite it not being supported in a convinient way, please tell me :)

Thanks, rHermes. 

Kevin Ford

unread,
Sep 6, 2016, 2:43:38 PM9/6/16
to DataStax Java Driver for Apache Cassandra User Mailing List
I made this work with a CustomCodec.  I'll describe via code below

I have an enum EmployeeType, here..
...
public enum EmployeeType {
   manager
, peon
 
}
...


Create a codec for the enum, this enum is a string enum as you can see

// create EnumNameCodec for any enums
 
EnumNameCodec<EmployeeType> employeeTypeNameCodec = new EnumNameCodec<EmployeeType>(EmployeeType.class);



// Register the enumCodec
  cluster
= Cluster.builder()
   
.addContactPoint(node)
   
.withCredentials(username, password)
   
.withCodecRegistry(
     
new CodecRegistry()
       
.register(employeeTypeNameCodec)
       
/* additional enum codecs or custom codecs here */ )
   
.build();

From there, any mapped classes that contain that enum will use this codec and store them as text.

Kevin Ford

unread,
Sep 6, 2016, 2:45:07 PM9/6/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Sorry about the above.. this was not a custom codec but an instance of EnumNameCodec, initialized with my Enum.


On Tuesday, February 10, 2015 at 5:10:32 AM UTC-8, Ziju Feng wrote:

Alexandre Dutra

unread,
Sep 7, 2016, 7:03:39 AM9/7/16
to DataStax Java Driver for Apache Cassandra User Mailing List
Hi,

The annotation @Enumerated has been removed in 3.0, thanks to JAVA-605. It had some limitations, and has been replaced with custom codecs, a much more flexible approach. You can read more about how to map enums in our online documentation.

--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.

To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
--
Alexandre Dutra
Driver & Tools Engineer @ DataStax
Reply all
Reply to author
Forward
0 new messages