-
Notifications
You must be signed in to change notification settings - Fork 470
When using toResources(), "links" is not correctly marshalled #493
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
A |
Sorry, I forgot: The controller is annotated with The same setup works with a single resource (i.e. not a list). Do you need any other information? |
Are you sure the HAL support is actually activated using |
Yes, it is. As I said, the same setup works if I'm return just one resource instead of a list. Oh, and we use spring-mvc-hateoas in version 0.21.0.RELEASE. |
I have the same issue using default As described here: http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-spring-hateoas: So:
Looks like the media type is ignored and it is always |
My feeling is, you're using the wrong (non-hal configured) jackson instance in your cases. It would be good to have a full example project on github to give you more detailed feedback. |
Unfortunately, it would be quite complicated to post an example project, since we would need to strip out all proprietary code. However, I can paste the relevant config snippets. The Controller, Resource and ResourceAssembler are as above.
|
You could probably workaround wrapping your collection in Instead of:
return Resources
However the rendering changes, as the list elements are embedded in an |
Is this related to #470, a PR that moved at add a UTF-8 based |
Hi @gregturn, I don't think so, no. Our problem highlights a different marshalling when using a |
I am seeing this too. Been struggling with it for a couple weeks and can't find the reason. |
Pretty sure you need to use Resources to get the collection to render properly. It's evident in the posted JSON where the top of the structure is an array not a map. Returning |
But if using a |
ResourceAssemblerSupport has some problems. That's why I wrote #591. In its current form, you should return a Resources with the contents of toResources inside it. |
Related to #416 |
@gregturn Makes sense, however, the |
If you look at #416, you'll notice the updated API stuffs that inside a |
@gregturn That indeed works and so does |
And when serving multiple resources in HAL, this is the proper format. non-_embedded is only for single items. |
Hm, not sure I can follow. return new Resources<>(assembler.toResources(sourceList)); which makes both steps pretty obvious. I'd argue that's SRP principle in practice. Maybe we can add a variant of that method ( |
To avoid confusion about what to return on a Spring MVC endpoint, change toResources to not return `List<D>`, but instead `Resources<D>`. This clearly ensures when used to construct Spring MVC endpoints, will return a type Spring HATEOAS will properly marshal. Related issues: #493 Related pull requests: #572
To avoid confusion about what to return on a Spring MVC endpoint, change toResources to not return `List<D>`, but instead `Resources<D>`. This clearly ensures when used to construct Spring MVC endpoints, will return a type Spring HATEOAS will properly marshal. Related issues: #493 Related pull requests: #572
To avoid confusion about what to return on a Spring MVC endpoint, change toResources to not return `List<D>`, but instead `Resources<D>`. This clearly ensures when used to construct Spring MVC endpoints, will return a type Spring HATEOAS will properly marshal. Related issues: #493 Related pull requests: #572
To avoid confusion about what to return on a Spring MVC endpoint, change toResources to not return `List<D>`, but instead `Resources<D>`. This clearly ensures when used to construct Spring MVC endpoints, will return a type Spring HATEOAS will properly marshal. Related issues: #493 Related pull requests: #572
This would be clearer if we didn't actually have a Additionally, people probably don't realize that Spring HATEOAS's hypermedia serialization doesn't kick in if a Spring MVC route don't return To support things, I'm adjusting #632 to have both. Or if they are simply returning that output on a Spring MVC route, they can adjust suitably. |
To avoid confusion about what to return on a Spring MVC endpoint, change toResources to not return `List<D>`, but instead `Resources<D>`. This clearly ensures when used to construct Spring MVC endpoints, will return a type Spring HATEOAS will properly marshal. To support people that have already built apps on top of Lists, include a `toList<D>` method that honors the old contract. Related issues: #493 Related pull requests: #572 Hack
To avoid confusion about what to return on a Spring MVC endpoint, change toResources to not return `List<D>`, but instead `Resources<D>`. This clearly ensures when used to construct Spring MVC endpoints, will return a type Spring HATEOAS will properly marshal. To support people that have already built apps on top of Lists, include a `toList<D>` method that honors the old contract. Related issues: #493 Related pull requests: #572
I'm using a method in a controller that returns a list of resources, built using toResources(). However, in the resulting json, the links are in a field called "links", and not "_links" as expected.
Example:
Code
Result:
The text was updated successfully, but these errors were encountered: