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
Ignore specific properties conditionally (Support @JsonView) #807
Comments
This feature isn't currently supported (jsonview). However, I would recommend that you not let the design of your system be dictated by a documentation library. Do what is right for your service and eventually the feature set of this library will catchup. Having said that, would love to get your feedback on how you've decided to go forward and what the gaps are in this library. |
👍 for supporting this feature. |
+1 |
1 similar comment
+1 |
+1 |
@AdelineJolie an alternative to JsonViews is to map DTOs to the model using a library such as mapstruct. (for information, mapstruct is used internally by springfox) |
Yeah I am going to look into this tonight. Will post an update. On Tue, Jan 12, 2016, 9:52 AM Dilip Krishnan notifications@github.com
|
@cbornet Thank you for the answer!. Yes using DTOs and domain objects (coupled with a mapping lib) was going to be our last resort. @mbazos looking forward for this, thank you! |
so what about now ? |
+1 |
3 similar comments
+1 |
+1 |
+1 |
Good afternoon. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
What are people's current workarounds for this? At the moment our swagger doc says a list operation returns a large model but actually only returns a few of those fields, and users have no way to tell which those fields are. |
Hi, @molexx If I correctly understand your question: There is one workaround with @ApiImplicitParams and you can use it with @ModelProperty(hidden = true) So, if you use one Model with the lot of endpoints but you need to hide some properties conditionally, then the only way is to hide some property at the all endpoints and then add it by @ApiImplicitParams at the few specific endpoints. For the return Models you can use @ApiOperation(response = Some.class) or @ApiResponse(response = Some.class) to override response Model. But, unfortunately, you will have to create all this classes with fields corresponding to the specific endpoint. |
Thanks @MaksimOrlov, yes that's the problem. @ApiImplicitParams and @ModelProperty will help in a couple of cases, thanks. The return models are the problem, a hierarchy of inherited classes can help to a point but there always seem to be some properties which don't fit in. I'm hoping that @JSONVIEW support will be straightforward to add when #1356 is done? |
+1 |
5 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
+1 |
6 similar comments
+1 |
+1 |
+1 |
👍 |
+1 |
+1 |
After day searching and find a way to work on this problem. I've realized that I'd googled this problem about
Cheers! |
@saboteurkid if I'm understanding correctly, the problem with Yes swagger can't handle optionals, so multiple models have to be extrapolated from each class and added separately (with a new name) to swagger; I suspect that's partly why this is tricky. |
@saboteurkid thanks for providing a work around for all the +1s. Also, the next release will also have support for this. |
@dilipkrish do you mean in the next release there'll be JsonView support? When is it scheduled? |
The next major release 3.0. Not scheduled yet. |
+1 |
@dilipkrish Do you have any news on the aviability of JsonView support or 3.0 ? |
@pcoste yes, @MaksimOrlov is working hard to help add support for that! |
@dilipkrish @MaksimOrlov Can we have an update on this highly expected feature ? |
I'm almost finished with that, just found a little bug and I'm going to fix it on this week and make a little refactoring to accomplish style rules. Will push it at the weekend. Then if @dilipkrish approve changes they will be merged to master, then feature will be available at the shapshot version. |
Our next iteration start on March 11, dev team will try latest snapshot mid March and come back to you with some informations :) Thanks |
@pcoste I've pushed changes. Waiting for feedback from @dilipkrish |
Branch with JsonView support has been merged to master and now available in 3.0.0-SNAPSHOT version. I would be grateful for feedback of this functionality. |
This demand took four years to solve. Thank you! @MaksimOrlov |
Do we have any example code for reference? If so please share I will be very helpfull |
I would like to hide some of my properties conditionally.
Usecase: I have an entity using at my rest controller with springfox at PUT and GET endpoints. At PUT endpoints I would like to hide
id
property whereas display at GET endpoints.At first glance I have considered to use something like
JsonView
at jackson. What is the proper solution to implement this functionality without duplicating or extending bean?The text was updated successfully, but these errors were encountered: