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

Cannot sort by property marked with JsonProperty.Access.READ_ONLY [DATAREST-1248] #1610

spring-projects-issues opened this issue May 28, 2018 · 2 comments


Copy link

@spring-projects-issues spring-projects-issues commented May 28, 2018

Norbert Somlai opened DATAREST-1248 and commented

If an entity field is marked read-only, sorting does not work.

For example:

public class User {
   @JsonProperty(access = JsonProperty.Access.READ_ONLY)
   private String name;

then api call


does not sort by name.

Removing the annotation makes sorting work again.

This problem has also been mentioned in a comment under DATAREST-976, but with an embedded property. It happens for non-embedded properties as well

Affects: 3.0.7 (Kay SR7), 3.1 RC1 (Lovelace), 2.6.14 (Ingalls SR14)

Backported to: 3.0.10 (Kay SR10), 2.6.15 (Ingalls SR15)

Copy link

@spring-projects-issues spring-projects-issues commented Jul 30, 2018

Florian Lüdiger commented

I would like to work on this issue, however I get stuck because of the following issue.

The error occurs in this line because the set of ignoredPropertyNames in the BeanDescription contains the attributes marked as read only, so the loop continues and the corresponding property is not added to the result set.

Debugging brought me to the strange behavior, you can reproduce as follows.
0. Simulate the error by including @JsonProperty(access = JsonProperty.Access.READ_ONLY) above this line

  1. Create a breakpoint at this line
  2. Step into the INTROSPECTOR.forDeserialization method
  3. Step until you reach the last line with the return statement
  4. When you evaluate desc.getIgnoredPropertyNames() here, you get an empty set.
  5. When you make another step now, you should be back in the fromJacksonProperties method and should now have the desc instance returned to the local description variable.
  6. I would expect that evaluating description.getIgnoredPropertyNames() now should return the same result as in step 4, however it returns a HashSet containing my two read only variables "isbn" and "title".

Can somebody explain this behavior to me or give me a heads up on how I can find the actual root of this error?

Copy link

@spring-projects-issues spring-projects-issues commented Aug 7, 2018

Oliver Drotbohm commented

That's in place now. We're now using the Jackson serialization configuration of an entity instead of the deserialization one (the latter not including read-only properties).

I guess the reason you see those properties change is that Jackson very often defers the calculation of information until it's actually needed. Some intermediate operation might just trigger the initialization of that field

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants