-
Notifications
You must be signed in to change notification settings - Fork 38.5k
@JsonView not working with Resources [SPR-12552] #17154
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
Comments
Sébastien Deleuze commented Hi David, I did some tests and found that using As a workaround, you can create an Even if Spring HATEOAS still depends on Spring 3.X by default, I think it could be fixed by using a Could you please create an issue on Spring HATEOAS bug tracker with a link to this one ? |
David Harrigan commented Hi, Perhaps I'm misunderstanding..but... I actually do inject my own ObjectMapper into the configuration and I can confirm that it is used. In AbstractJackson2HttpMessageConverter (4.1.3 Release), lines 222-229 are being invoked, i.e., serializationView != null is true, and the objectMapper.writerWithView is being invoked (with the Summary view being the View that has been choosen). Are you saying that this is then ignored by Hateos? I am not using EnableHypermediaSupport as well, as if you are referring to Lines 624-638 (defaultMethodArgumentResolvers) and lines 642-655 (basicObjectMapper) of RespositoryRestMvcConfiguration (spring-data-rest-mvc (2.3.0.M1)). These are not being used (no breakpoint was activated on application start, or message serialization). In "defaultMessageConverters" in RespositoryRestMvcConfiguration, none of the messageConverters.add are being used. So, in reality, I'm not using the EnableHypermediaSupport as far as I can tell. For example, here is where I inject the ObjectMapper into the MappingJackson2HttpMessageConverter.
-=david=- |
Sébastien Deleuze commented If you are using your own When |
David Harrigan commented Hi, Yes, I'm using it, and it is set to false. However, I believe I've also discovered the cause of the Issue. On org.springframework.hateoas.Resource, getContent (line 74), is marked as Proof: This works:
Result:
This does not:
Result:
It appears that using the JsonUnwrapped attribute, causes the View not to work as expected. Do you think the issue now is with Jackson or with Hateos Resource? |
Sébastien Deleuze commented I think this is the expected behavior: with In your initial comment, all the data was serialized, that why I thought you had My proposal to make that works would be to configure @JsonView(Foo.Summary.class)
private String name;
@JsonView(Foo.Full.class)
private String password; |
David Harrigan commented Hi, That doesn't appear to work. Setting DEFAULT_VIEW_INCLUSION = true, and having a "Summary" view on a property and a "Full" view on another property, then having the "Summary" view on the controller, just causes all the properties to be serialised (in effect, the "Summary" view does not get applied). If I set the DEFAULT_VIEW_INCLUSION = false, then nothing comes out. |
Sébastien Deleuze commented Could you have a look to this sample project I have created ? Please provide a reproduction project if that does not help. |
Sébastien Deleuze commented Hi David Harrigan, could send me your feedback ? |
David Harrigan commented Hi! I've not had a chance to try and reproduce this issue yet. I've also moved on from it a bit, since I've found that using this https://jira.spring.io/browse/DATACMNS-618 gives me more flexibility and choice on which data to return depending on a parameter passed in. I'm happy enough for you to close this JIRA if you believe it appropriate. Thank you. -=david=- |
Sébastien Deleuze commented OK thanks. Since the sample project I have created seems to demonstrate the expected behavior, I resolve this issue as "Cannot Reproduce" until someone fork and modify it to reproduce the issue. |
David Harrigan commented Hi, Okaydokey :-) Thank you for your care and attention to the issue :-) -=david=- |
Jonathan Rodrigues de Oliveira commented Hey guys.
The method "a" works ok. The method "b" returns and empty object "{}". Thanks. |
Sébastien Deleuze commented Hi, did you set |
Jonathan Rodrigues de Oliveira commented Hey. If I set default view inclusion to true, the method "b" returns the full objects, with all fields. The config and the entity are like this:
I tried to annotate the getters with |
Jonathan Rodrigues de Oliveira commented Hi Sébastien. I've made some tests, and Thanks. |
Madanraj Sadasivam commented Hi Guys, I am having the same issue. RestController returns empty json if annotated with
I can send you further details of my code, and spring/jackson version, if it will help. Please let me know. I also think we should reopen the ticket. |
Sébastien Deleuze commented Yes please send me your sample project, I will have a look. |
Madanraj Sadasivam commented Hi Sebastien, The sample project is below. Try running on a web server and access the url "http://localhost:8080/SpringSampleProject/user" with both GET and POST to see the difference. RestController is "com.aakam.sample.rest.UserController" GitHub Repo |
Sébastien Deleuze commented As explained in previous comments, when using classes with non Another (untested) option may be to use Jackson Mixins to specify that the Could you confirm that it works as expected? |
Madanraj Sadasivam commented Yes, it works. Thanks. |
David Harrigan opened SPR-12552 and commented
Hi,
Spring 4.1.3
Jackson 2.4.4
I have a class that looks something like this:
and a controller that looks something like this:
However, when I get the values returned, they include everything:
As you can see, the
@JsonView
is not being honoured during the serialization of the Content data as the "password" field is being included in the serialization.Thank you.
-=david=-
Affects: 4.1.3
The text was updated successfully, but these errors were encountered: