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

How about adding more explict writing/reading converter interface? #2968

Closed
hqsz opened this issue Oct 30, 2023 · 3 comments
Closed

How about adding more explict writing/reading converter interface? #2968

hqsz opened this issue Oct 30, 2023 · 3 comments
Labels
status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged

Comments

@hqsz
Copy link

hqsz commented Oct 30, 2023

Hello, thanks for supporting spring framework :)

It appears that Spring Data's converter system currently distinguishes between writing converters and reading converters based on annotations.

		Class<?> type = converter.getClass();
		boolean isWriting = type.isAnnotationPresent(WritingConverter.class);
		boolean isReading = type.isAnnotationPresent(ReadingConverter.class);

Is there a specific reason for controlling this solely through annotations? If there isn't a particular reason, how do you feel about adding WritingConverter and ReadingConverter interfaces that extend the Converter interface to define converters more explicitly?

@hqsz
Copy link
Author

hqsz commented Oct 30, 2023

I already reported to spring-projects/spring-framework#31260. but I moved here because they said this place was more suitable

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 30, 2023
@mp911de
Copy link
Member

mp911de commented Nov 1, 2023

Spring Data follows the one-way nature of Spring Converters where each converter is specified by its own type. Annotations are only required to disambiguate converters if their type signatures cannot be mapped to store-native types or when we cannot determine the conversion direction (store to model, model to store).

Having a separated model makes it easier to implement only one side of the conversion as we have a lot of cases of one-way usage.
We also provide ConverterBuilder as middleground for a more API-oriented approach to configuring converters.

Taking a step back, what is the thing that you're looking for (i.e., what problem do you want to solve)?

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Nov 1, 2023
@hqsz
Copy link
Author

hqsz commented Nov 2, 2023

yeah i agree about your comment.

I encountered this issue with spring & mongo. so i want to avoid ambiguity of converter interface In terms of service developer. maybe adding validation to MongoCustomConversions can be a workaround solution

Thanks for answering! i'll close this issue. if you have any other opinion. feel free to reopen this issue. Have a good day 👍

@hqsz hqsz closed this as completed Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants