spring-projects / spring-data-commons

Spring Data Commons. Interfaces and code shared between the various datastore specific implementations.

Home Page:https://spring.io/projects/spring-data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How do I add converter from Instant to org.joda.time.DateTime to spring-data-commons-3.2.1 and spring-data-cassandra-4.2.1

thaparraj opened this issue · comments

I started getting the exception after I upgraded to spring-data-commons-3.2.1 and spring-data-cassandra-4.2.1.

I added the custom conversions (below) but still get the error

@configuration
public class CassandraConfig {
...
@bean
CassandraCustomConversions cassandraCustomConversions() {
List<Converter> converters = new ArrayList<>();
converters.add(new InstantToDateTimeConverter());
converters.add(new DateTimeToInstantConverter());
CassandraCustomConversions ccv = new CassandraCustomConversions(converters);
return ccv;
}
class DateTimeToInstantConverter implements Converter<DateTime, java.time.Instant> {
@OverRide
public java.time.Instant convert(DateTime source) {
return source.toDate().toInstant();
}
}
class InstantToDateTimeConverter implements Converter<java.time.Instant, DateTime> {
@OverRide
public DateTime convert(java.time.Instant source) {
return new DateTime(Date.from(source));
}
}
...
}