Add support for specifying array serialization for a particular link relation
See original GitHub issueThis is a follow-up on #288, as suggested in last comment on that issue.
We’re including item
link relation (see https://tools.ietf.org/html/rfc6573#section-2.1) to _links
in our HAL responses that return collections/pages.
The code that handles this in @Controller
handler method looks something like this:
for (MyResource resource : resources) { // resources is an instance of PagedResources
resources.add(resource.getLink(Link.REL_SELF).withRel("item"));
}
This works fine when actually there are multiple resource in the collection/page:
"_links": {
"item": [
{
"href": "http://localhost:8080/api/MyResource/1"
},
{
"href": "http://localhost:8080/api/MyResource/2"
}
]
}
However, when there is a single resource in the collection/page, then we don’t get an array:
"_links": {
"item": {
"href": "http://localhost:8080/api/MyResource/1"
}
}
Obviously, this isn’t ideal from the perspective of client that consumes the service. It would be nice if Spring HATEOAS would provide a support for explicitly specifying array serialization for a certain link relations.
Issue Analytics
- State:
- Created 5 years ago
- Comments:18 (17 by maintainers)
Top Results From Across the Web
allowing multiple link relation types in rel in the JSON ... - GitHub
However, in the JSON serialization you define, it appears that it can only support a single link relation type.
Read more >How to serialize SqlAlchemy result to JSON? - Stack Overflow
It allows you to create serializers to represent your model instances with support to relations and nested objects. Here is a truncated example...
Read more >Customizing Serializers - Ember Data - Ember Guides
There are two ways to define a custom serializer. First, you can define a custom serializer for your entire application by defining an...
Read more >The Serializer Component (Symfony Docs)
As you can see in the picture above, an array is used as an intermediary between objects and serialized contents. This way, encoders...
Read more >Serialization and Deserialization in Java with Example
To make a Java object serializable we implement the java.io.Serializable interface. The ObjectOutputStream class contains writeObject() method ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A rel is not really tied to a controller nor to a domain type. I guess we can provide a way to configure patterns to match, so that you can simplify the setup to configure this based on the curie used.
Why don’t you open a new ticket instead of commenting on one that’s been closed and released.