spring-data-rest
spring-data-rest copied to clipboard
DomainObjectReader doMerge fails for writable @JsonAnySetter properties
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.