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

DATAREST-1383 causes top level properties with @JsonSetter to be missed. [DATAREST-1573] #1911

Open
spring-projects-issues opened this issue Oct 22, 2020 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

Joseph Valerio opened DATAREST-1573 and commented

We just upgraded to SpringBoot 2.3.2.

We are using spring datarest 3.3.2 with JPA against a RDBMS

We use a PATCH to update our user's passwords.  We have a setter on our User Object setPassword() annotated with @JsonSetter, but there is no corresponding persisted property.  This method is used to set the persisted encryptedPassword property on the user.  The following commit on DomainObjectReader causes this to no longer work:

c616c53

229:       if (!mappedProperties.hasPersistentPropertyForField(fieldName)) {				 
230:           i.remove();
231:           continue;
232:       }

The i.remove on line 230 removes the password property from consideration since it is not a PersistentProperty  

If this property is not removed, it will cause the setter to be invoked at line 285:

 

return mapper.readerForUpdating(target).readValue(root);

 

If we change the Method to a PUT this works correctly, but it should also work for patch.

If you are not following my explaination, I can create a test project to expose the issue on request


1 votes, 2 watchers

@spring-projects-issues
Copy link
Author

Joseph Valerio commented

I think you need something like this:

      if (!mappedProperties.isWritableProperty(fieldName)) {

        if(!isPropertyJsonWritable(target, fieldName))
          i.remove();

        continue;
      }

...

  private boolean isPropertyJsonWritable(Object bean, String fieldName) {

    BeanWrapper wrapper = new BeanWrapperImpl();
    if(wrapper.isWritableProperty(fieldName)) {
      if(wrapper.getWrappedClass().getAnnotation(JsonSetter.class) != null)
        return true;
      if(wrapper.getWrappedClass().getAnnotation(JsonProperty.class).access() == Access.READ_ONLY)
        return false;

      // default to writable if nothing else
      return true;
    }

    return false;

  }

I know this is brute force-ish, but it conveys the idea that I am proposing.  We can not just rely on the persistent property information for determining if this property is writable

@spring-projects-issues
Copy link
Author

bschoenmaeckers commented

duplicate of  DATAREST-1524

@darioseidl
Copy link
Contributor

darioseidl commented Jan 18, 2022

I believe this is essentially the same issue as #1928 edit: and also #1881.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants