DomainObjectReader doMerge fails for writable @JsonAnySetter properties

Aperta
#2,407 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@odrotbohm ci sta già lavorando.

Dal 12/8/2024.

  • #2408 di @msparer — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

status: waiting-for-triage

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.

Lingua principale
Java
Stelle
957
Fork
570
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di spring-projects/spring-data-rest

Tutte le issue di spring-projects/spring-data-rest

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.