Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converter should not ignore @CassandraType for collection like type [DATACASS-743] #912

Closed
spring-projects-issues opened this issue Mar 20, 2020 · 2 comments
Assignees
Labels
type: bug

Comments

@spring-projects-issues
Copy link

spring-projects-issues commented Mar 20, 2020

Łukasz Świątek opened DATACASS-743 and commented

Collection like data types will ignore declared @CassandraType if CustomConverter is is registered

For example, if we have following entity

@Value
@Table
static class Sample{
   @Id String id;

   @CassandraType(type = CassandraType.Name.TEXT)
   List<String> collectionAsString;
   @CassandraType(type = CassandraType.Name.LIST, typeArguments = CassandraType.Name.TEXT)
   List<String> collectionAsList;
}
 

and register converter List<String> <-> String then it will be applied to field collectionAsList as well even though it is explicitly marked as LIST

Note, even if we were to change argument type to int for the collectionAsList the List<String> -> Sring converter will still be applied which might be an issue on itself

 

Similarly, if mark collection type with 2 different cassandra types, only one of converters will be used for both

@Value
@Table
static class SimpleSample{
   @Id String id;

   @CassandraType(type = CassandraType.Name.TEXT)
   byte[] bytesAsHexString;
   @CassandraType(type = CassandraType.Name.BLOB)
   byte[] bytesAsBlob;
} 

 

 

 


No further details from DATACASS-743

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 20, 2020

Mark Paluch commented

@CassandraType is a general hint to enforce a particular type especially during schema generation. It does not depend on the actual existence of a registered converter. The general converter attempts to convert the top-level value into the Java type that is associated with the Cassandra type. Type arguments (typeArguments = CassandraType.Name.TEXT) are not considered yet for Collections and map key-value pairs. It would make sense to fix that aspect.

There's no way how to properly convert a collection type into a TEXT or INT representation, therefore these annotations have no effect. It would make sense to rather throw an exception in such case to aid debugging.

When you have a converter registered for Collection<?> to String and vice versa, then we do not consider @CassandraType. That is a known issue and should be addressed when revising collection conversion

@spring-projects-issues
Copy link
Author

spring-projects-issues commented Mar 23, 2020

Mark Paluch commented

Fixing this issue requires new API as Cassandra types are associated with auxiliary details such as user type names and specific data types, so we decided to introduce ColumnType, CassandraColumnType and ColumnTypeResolver. This refactoring is part of DATACASS-470

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug
Projects
None yet
Development

No branches or pull requests

2 participants