Skip to content

LocalDateTime converter compatible with Java SDK #1203

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

Open
mikereiche opened this issue Aug 25, 2021 · 3 comments
Open

LocalDateTime converter compatible with Java SDK #1203

mikereiche opened this issue Aug 25, 2021 · 3 comments
Assignees
Labels
type: enhancement A general enhancement

Comments

@mikereiche
Copy link
Collaborator

mikereiche commented Aug 25, 2021

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 mikereiche self-assigned this Aug 25, 2021
@mikereiche mikereiche added the type: enhancement A general enhancement label Aug 25, 2021
@mikereiche
Copy link
Collaborator Author

It looks like this has been added.

@mikereiche
Copy link
Collaborator Author

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
Copy link
Collaborator Author

mikereiche commented Nov 30, 2022

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 (?).

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

No branches or pull requests

1 participant