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

@JsonIgnoreProperties doesn't work in certain conditions #12968

Closed
GuiRitter opened this issue Apr 25, 2018 · 3 comments
Closed

@JsonIgnoreProperties doesn't work in certain conditions #12968

GuiRitter opened this issue Apr 25, 2018 · 3 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@GuiRitter
Copy link

Hi everyone.

As per this discussion and others I read elsewhere, it should be possible to use @JsonIgnoreProperties to hide properties of entity properties. However, I performed several tests and sometimes it works, sometimes it doesn't.

In the simplest case, an User entity that has an @OneToOne relationship with an UserPermission entity cannot hide UserPermission's hidden property via @JsonIgnoreProperties("hidden"), when accessing a @RepositoryRestResource via REST.

If the repository is used with excerptProjection = UserProjection.class, and the projection uses UserPermission instead of UserPermissionProjection, it works. If both are projections, it doesn't work.

By @Autowireding an ObjectMapper, doing the serialization in a @RepositoryRestController and printing the result with System.out, any case works.

Here's a project that reproduces the issue. Clone/download, build with Maven, run DemoApplication.java and access http://localhost:8080/users from any browser. The hidden properties should not appear.

Thanks in advance.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 25, 2018
@robsonfar
Copy link

This is a very important annotation that should work, because it's also used to control Bidirectional relationship. With @JsonManagedReference and @JsonBackReference it could be controlled, but we lost the property with the @JsonBackReference, and sometimes we really need that property when working directly with the Entity. @JsonIgnoreProperties fills this gap, since we can controll in parent level. It would be really great if it worked.

@philwebb
Copy link
Member

philwebb commented Apr 26, 2018

@GuiRitter Sorry to bounce you about issue trackers but I think that this is a Spring Data REST issue. I've raised DATAREST-1236. Thanks for the sample project, it was very helpful in determining what was going on.

@philwebb philwebb added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 26, 2018
@GuiRitter
Copy link
Author

Thanks for raising the issue in Jira and sorry for posting in the wrong project. Earlier tests made me believe it was an issue with Boot and that it wouldn't happen without it, but I couldn't (in a reasonable amount of time) reproduce the same use case without Boot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

4 participants