-
Notifications
You must be signed in to change notification settings - Fork 478
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
Support for @JsonView Jackson annotation #351
Comments
Does Pull request 359 solve your issue? |
Sorry, Tinne, could you provide a slightly more detailed explanation on how to use? |
Sure. Say, you have a detail view for some "configuration item" which is represented by a model bean: @RequiredArgsConstructor @AllArgsConstructor
public class Configuration extends ResourceSupport {
@Getter
private final String guid;
@Getter
private final String name;
@Getter @Setter
private String description;
@Getter @Setter
private boolean active;
} and you need a collection view with a lot of "Configuration" objects but only minimal data, say, guid and name. Then, annotating these by a custom JsonView interface annotation like this, @RequiredArgsConstructor @AllArgsConstructor
public class Configuration extends ResourceSupport {
public interface ConfigurationOverview extends Link.LinkView {}
@Getter
@JsonView(ConfigurationOverview.class)
private final String guid;
@Getter
@JsonView(ConfigurationOverview.class)
private final String name;
...
} and annotating the overview rest controller like this, RestController
public class ConfigurationController {
@RequestMapping(value = "/configuration", method = GET)
@JsonView(Configuration.ConfigurationOverview.class)
public HttpEntity<Configuration[]> allConfigurations() { ... }
} you get an JSON 'view' of the configurations. |
Thanks Tinne. |
In order for Resource and Resources to work, an additional patch was necessary, which extends the coverage of the Link.LinkView interface to the content property of these two container classes. It has now been added to the pull request, please give it a try. |
Great work Tinne, It works like a charm. |
I followed the convention introduced by some introductory blog entry, but am free for any alterations. Maybe lifting the marker interface to be a top-level module is also more spring-alike. What do you think? |
Yes, I think the View interface should be out of Link class. |
The marker interface is now a top-level module called ResourcesLinksVisible. |
It's much clearer for me now. Of course, it keeps working. |
See the discussion on the PR. |
I'm trying to use @JSONVIEW inside my Resourse following your example. Unfortunately I don't find LinkView neither ResourcesLinksVisible. Could you help me with a more up to date example? Thanks |
Currently, with the default behaviour, it your controller returns Resource, Resources or PagedResources objects, Jackson Mapper is not able to manage @JSONVIEW properly.
It is posible customize Mapper or MixInAnnotation 's in any way to get this work?
The text was updated successfully, but these errors were encountered: