Skip to content

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

Closed
@CybAtax

Description

@CybAtax

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.

Activity

christophstrobl

christophstrobl commented on May 28, 2024

@christophstrobl
Member

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

added and removed
for: team-attentionAn issue we need to discuss as a team to make progress
on Jun 17, 2024
added this to the 4.2.10 (2023.1.10) milestone on Aug 28, 2024
added 4 commits that reference this issue on Aug 28, 2024
8077b18
f8aa915
791f8b2
bc59095

5 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Null-Values from custom converters are stored in document · Issue #4710 · spring-projects/spring-data-mongodb