spring-data-couchbase icon indicating copy to clipboard operation
spring-data-couchbase copied to clipboard

LocalDateTime converter compatible with Java SDK

Open mikereiche opened this issue 4 years ago • 3 comments

LocalDateTime converter compatible with Java SDK. This was requested by a specific customer that uses both spring-data-couchbase and the Java SDK.

private CouchbaseJsr310Converters() {
...
	public static Collection<Converter<?, ?>> getConvertersToRegister() {
		List<Converter<?, ?>> converters = new ArrayList<>();
		// converters.add(NumberToLocalDateTimeConverter.INSTANCE);
		// converters.add(LocalDateTimeToLongConverter.INSTANCE);
		converters.add(LocalDateTimeToStringConverter.INSTANCE);
		converters.add(StringToLocalDateTimeConverter.INSTANCE);
	@ReadingConverter
	public enum StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {

		INSTANCE;

		@Override
		public LocalDateTime convert(String source) {
			return source == null ? null : LocalDateTime.parse(source);
		}
	}

	@WritingConverter
	public enum LocalDateTimeToStringConverter implements Converter<LocalDateTime, String> {

		INSTANCE;

		@Override
		public String convert(LocalDateTime source) {
			return source == null ? null : source.toString();
		}

	}
	```

mikereiche avatar Aug 25 '21 01:08 mikereiche

It looks like this has been added.

mikereiche avatar Jan 12 '22 19:01 mikereiche

I'm not sure about that last comment - it does NOT appear to have been added. There is still only the conversion from/to Number (not string).

mikereiche avatar Nov 30 '22 21:11 mikereiche

It seems that adding just StringToLocal... converters would allow spring data couchbase to read what was written by the java sdk. Writing is a bit tricky, as changing the serialization to String (on write) would cause problems for older versions of spring-data-couchbase that do not have the StringToLocal... converters. On the other hand, the current situation of serializing to Number on write (maybe) causes problems for reading with the java sdk. Maybe the java sdk can deserialize Numbers to LocalDateTime etc (?).

mikereiche avatar Nov 30 '22 21:11 mikereiche