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

Null-Values from custom converters are stored in document #4710

Open
CybAtax opened this issue May 28, 2024 · 1 comment · May be fixed by #4728
Open

Null-Values from custom converters are stored in document #4710

CybAtax opened this issue May 28, 2024 · 1 comment · May be fixed by #4728
Assignees
Labels
type: bug A general bug

Comments

@CybAtax
Copy link

CybAtax commented May 28, 2024

With the release of spring-boot 3.2.0 a change to the deserialization was noted, which was addressed in a previous issue: #4571

The change itself makes sense, as the serialized null value should be respected. The analysis surprisingly led to a different issue as null-values are being serialized despite the defaulting setting of not writing null-values as specified here: https://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/mapping/Field.html#write()

However, that check appears to only apply to unconverted values, as seen in:

while the value retrieved from a custom converter is not checked for nullity. The Javadoc specifically allows returning null from a Converter (https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/convert/converter/Converter.html#convert(S))

One specific use case may be reducing data in the database and thus converting certain values to null - with the intention of them not being written. With the provided examples above however, this does not appear to be the case.

Additionally it is interesting, that the Converter Javadoc specifies that the source may never be null (https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/convert/converter/Converter.html#convert(S)) - even though this can occur when converting a value to null during serialization and then deserializing said value with the corresponding ReadingConverter.

An example project verifying the issue can be found at https://github.com/CybAtax/null-serialization-demo/tree/main

Any assistance in how to resolve this will be greatly appreciated.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 28, 2024
@christophstrobl
Copy link
Member

Thank you @CybAtax for raising this ticket. Let me take it to the team.

@christophstrobl christophstrobl added the for: team-attention An issue we need to discuss as a team to make progress label May 28, 2024
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged for: team-attention An issue we need to discuss as a team to make progress labels Jun 17, 2024
@mp911de mp911de assigned mp911de and christophstrobl and unassigned mp911de Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants