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

DomainObjectReader doMerge fails for writable @JsonAnySetter properties #2407

Open
msparer opened this issue Aug 8, 2024 · 0 comments · May be fixed by #2408
Open

DomainObjectReader doMerge fails for writable @JsonAnySetter properties #2407

msparer opened this issue Aug 8, 2024 · 0 comments · May be fixed by #2408
Assignees
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@msparer
Copy link

msparer commented Aug 8, 2024

Hi!

When using PATCH for objects that use @JsonAnySetter for deserialization and therefore don't have a corresponding property in MappedProperties, DomainObjectReader#doMerge fails. This used to work in previous versions of this class, when

if (!mappedProperties.hasPersistentPropertyForField(fieldName))

was used (without removing the field from deserialization, see changes in commit and commit ). Now

if (!mappedProperties.isWritableProperty(fieldName)) {

checks whether the property is writable (which is an improvement). But this also returns true if the class to merge contains an @JsonAnySetter. This means that the following call

PersistentProperty<?> property = mappedProperties.getPersistentProperty(fieldName);

returns null and the call after this

Optional<Object> rawValue = Optional.ofNullable(accessor.getProperty(property));

Throws the error.

The solution IMHO is a simple null check before the accessor.getProperty call like

if (property == null) {
  continue;
}

This lets @JsonAnySetter handle the further deserialization, as I understand was the intention in previous versions and should be now.

I confirmed this fix with a test case, see referenced pull request.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 8, 2024
msparer pushed a commit to msparer/spring-data-rest that referenced this issue Aug 8, 2024
@msparer msparer linked a pull request Aug 8, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants