I have enum with inner value:
public enum Test {
A("a");
private String value;
Test(String value) {
this.value = value;
}
@Override
public String toString() {
return this.value;
}
}
And I use it as a parameter in Spring Data Cassandra @Query. Also I added read and write converter to just for parsing "a" -> A and back. I was expected that if I send A as parameter the query will be generated by converters to. But the query was like "... my_enum = 'A'" instead of 'a'.
I was trying to debug spring sources and found this part of code org/springframework/data/spring-data-cassandra/1.5.9.RELEASE/spring-data-cassandra-1.5.9.RELEASE-sources.jar!/org/springframework/data/cassandra/convert/MappingCassandraConverter.java:799:
// Cassandra has no default enum handling - convert it either to string
// or - if requested - to a different type
if (Enum.class.isAssignableFrom(value.getClass())) {
if (requestedTargetType != null && !requestedTargetType.isEnum()
&& getConversionService().canConvert(value.getClass(), requestedTargetType)) {
return getConversionService().convert(value, requestedTargetType);
}
return ((Enum<?>) value).name();
}
Looks like if parameter is enum - converters never be used. How can i deal with it? Thank you.
A.toSring()
instead of allA
s. But i'm guessing you are looking for a more automatic way of conversion...