-
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 HATEOAS-Links in Json-Views #387
base: main
Are you sure you want to change the base?
Conversation
when filtered by providing a tooling interface, now complete. Signed-off-by: Karsten Tinnefeld <k.tinnefeld@googlemail.com>
Signed-off-by: Karsten Tinnefeld <k.tinnefeld@googlemail.com>
Signed-off-by: Karsten Tinnefeld <k.tinnefeld@googlemail.com>
Signed-off-by: Karsten Tinnefeld <k.tinnefeld@googlemail.com>
Signed-off-by: Karsten Tinnefeld <k.tinnefeld@googlemail.com>
Signed-off-by: Karsten Tinnefeld <k.tinnefeld@gmail.com>
Signed-off-by: Karsten Tinnefeld <k.tinnefeld@googlemail.com>
Signed-off-by: Karsten Tinnefeld <k.tinnefeld@gmail.com>
Hi @tinne I've tested your forked branch (https://github.com/tinne/spring-hateoas/tree/resources-links) and it's not working for me. Check my .diff file (spring-hateoas.txt). It includes changes to fix this issue. |
Hi @sergiorc , please check with my test Regarding the patch to The third change regarding |
Hi @tinne, sorry by the delay. You can check it using your forked branch (without my changes) and removing @JSONVIEW(NewJsonView.class) from ResourceLinksVisibleTest.BeanWithView class. As long as I understand, this should make a lot of tests fail, but they keep working! |
I don't quite get the root intention of that PR. If you don't want to expose any links, simply don't return |
The root intention of the PR is to provide a uniform data model for overview and detail views of some model, perhaps to several layers. The need came from a set of REST services which had methods a) give me a long list of all available The proposed solution is to have the result set contain a Problem is, when applying any JSON view, several I hope this explanation makes things a bit clearer. Feel free to check again if this is not all clear. I could also provide some demo code if needed. |
I still don't think we can introduce the change as all of a sudden people would have to include the JSON View class you used in their setup. So we all of a sudden run into a brittle scenario that breaks the media-type compatibility. TBH, I think JSON Views are a pretty broken concept in the first place, that's why we didn't bother supporting it so far. It might be bad news but the PR is pretty much acknowledging this. Not because you did anything wrong or bad but because of the flawed concept. I just checked the Jackson docs again and it seems like you can just configure |
I know JSON Views are not a very orthodox practice from REST architecture perspective, but obtaining a reduced -filtered- version of your resource is a common requirement in a lot of cases (usually in embedded collection resources). That said, I think PR inclusion should not produce any impact if the behaviour is: |
It seems to me that the level of effort to make two models, a normal and detailed, would be about the same as trying to wire up this JsonView stuff. And simpler. I think this is an attempt to optimize too heavily for DRY, and it seems burdensome. I'd rather just manage the two POJOs and have either two end points, or one endpoint driven by a parameter that returns Object. |
Effort can be similar in small project, but think in big ones, REST API's publishing hundreds of resources with 'filtered entities' requirements. You'll have to maintain hundreds of duplicated POJO's and/or enpoints. I don't think this PR really introduce complexity in spring-hateoas project, and also, it improves chances of HATEOAS adoption in any project. I have in mind REST projects using Spring MVC + JSON Views looking for HATEOAS support. Other REST implementations (e.g. Jersey), include entity filtering as a native feature. |
Let me emphasize on @sergiorc's argument: spring-hateoas is currently broken with regard to JSON views and the tests go some way to show this effect. This is surely a proof nobody needs in a regression test and was only included to demonstrate why the fix is added. The PR introduces an interface noone is forced to use of even take notice of, and spring-hateoas will continue to work as it used to (no problem without views, something somehow silly happens under views). Just in case anyone needs to apply JSON views, effectively adding some few annotations referencing a trivial interface to the HATEOAS library adds this support almost effortlessly for those who can make use of it. Also, it is not only a matter of DRY, but of defining designed-exactly-to-their-use APIs without bothering about filtering the result of a lower layer result set in a multi-layer (e.g., micro service) architecture. |
@tinne Hi tinne, This is a very useful future. I want to know when this feature will be available for release. can I apply patch and use this feature by assuming this will be available for next release ? |
@srinivaspr, this is up to @olivergierke to decide. Please convince him by explaining what you would like to do with the feature. |
Not sure what is the status with this but I would personally enjoy this feature if it were available. I have a fairly complex data model with nested documents in Mongoldb. Depending on the type of query I would like to show different level of details. For example in a |
Hi @olivergierke , have you made a decision? |
4ebc1be
to
266ad50
Compare
Not sure which feedback this is still waiting for. KIndly elaborate on the labeling. |
@olivergierke , have you made a decission? |
@tinne Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@tinne Thank you for signing the Contributor License Agreement! |
One aspect that I have not heard brought up is security. I have domain objects that I want to expose portions of based on User Roles. The solution to this is quite simple if @JSONVIEW is enabled. Creating two different domain models, as suggested, is a non starter. That would entail entirely different logic and domain models creating unnecessary complexity. If this is possible via a combination of Spring Security + HATEOAS projections I am unaware. |
Is it possible to have this feature? |
Any planned date/release for this feature? |
Hi @tinne and @odrotbohm , |
@ajitkumargiri , need help. I have Java object public class OrderDto extends AbstractDto<OrderDto> {
@Valid
private UserDto user;
@Valid
private GiftCertificateDto giftCertificate;
@JsonView(View.FindOrderForUser.class)
private BigDecimal price;
@JsonView(View.FindOrderForUser.class)
private LocalDateTime purchaseDate;
} Why, when returning this @GetMapping(UrlMapping.ORDER_USER)
@JsonView(View.FindOrderForUser.class)
public EntityModel<OrderDto> findOrderForUser(@PathVariable long userId, @PathVariable long orderId) {
OrderDto orderDto = orderService.findOrderForUser(orderId, userId);
return EntityModel.of(orderDto);
} Result: {} But if I return a simple @GetMapping(UrlMapping.ORDER_USER)
@JsonView(View.FindOrderForUser.class)
public OrderDto findOrderForUser(@PathVariable long userId, @PathVariable long orderId) {
return orderService.findOrderForUser(orderId, userId);
} Result: {
"createDate": "2021-06-25T21:38:01",
"lastUpdateDate": "2021-05-21T17:19:06"
} But in this case, it is necessary that the {
"price": 1.00,
"purchaseDate": "2021-11-15T10:38:45.193",
"_links": {
"self": {
"href": "http://localhost:8080/orders/1"
}
} Also in
|
2e02d7a
to
856b6b9
Compare
5828e78
to
e643c37
Compare
The @JSONVIEW annotation supports filtering class trees in order to provide custom views on specific partial data, cf. eg. https://spring.io/blog/2014/12/02/latest-jackson-integration-improvements-in-spring
The main purpose of this patch is to provide a means of views including the links properties of REST models using Resource(s). See the tests in ResourceLinksVisibleTest for further discussion.
Usage: extend ResourceLinkView to denote your view properties.
(This pull request supersedes pull request #359 and solves issue #351.)