You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NullValuePropertyMappingStrategy.IGNORE strategy ignored for Optional fields #4128
The NullValuePropertyMappingStrategy.IGNORE strategy should be applied to Optional fields in exactly the same way as it is applied to other field types. Its behavior is clearly defined in the Javadoc:
If a source bean property equals null the target bean property will be ignored and retain its existing value.
Instead, NullValuePropertyMappingStrategy.IGNORE is effectively ignored for Optional fields. This also doesn't align with common JSON mapping semantics, where an absent field is ignored (i.e. nothing is done), while an explicitly provided null value is mapped to Optional.empty().
This approach is often used to cover patch semantics during mapping. A patch needs to distinguish between three states, which is why Optional is used:
null - ignore the field and keep its existing value
Optional.empty() - clear the field by setting it to null
Optional.of(value) - update the field with the wrapped value
Previously, NullValuePropertyMappingStrategy.IGNORE did exactly what was expected: it applied the necessary null checks and preserved the distinction between an absent field and an explicitly provided empty value.
Quite a few production systems are already built around these semantics. The recent changes therefore introduce breaking changes for existing applications that rely on this distinction.
Actual behavior
The NullValuePropertyMappingStrategy.IGNORE strategy is simply ignored, and no null check is generated:
Steps to reproduce the problem
Create source and target objects with Optional field:
I've looked into the problem and the related PR #4124. As I understand it, the three-state PATCH behavior with NullValuePropertyMappingStrategy.IGNORE is not covered by that PR.
I'd like to investigate the generated mapping logic, implement a fix, and add regression tests for null, Optional.empty(), and Optional.of(value).
Is anyone currently working on this issue, and would a PR addressing this behavior be welcome?
Activity
nu11Po1nter1 commentedon Oct 13, 2026
Hi, I'd be interested in working on this issue.
I've looked into the problem and the related PR #4124. As I understand it, the three-state PATCH behavior with
NullValuePropertyMappingStrategy.IGNOREis not covered by that PR.I'd like to investigate the generated mapping logic, implement a fix, and add regression tests for
null,Optional.empty(), andOptional.of(value).Is anyone currently working on this issue, and would a PR addressing this behavior be welcome?
Thanks!