question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for specifying array serialization for a particular link relation

See original GitHub issue

This 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:closed
  • Created 5 years ago
  • Comments:18 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
odrotbohmcommented, Feb 14, 2019

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.

0reactions
gregturncommented, Aug 31, 2020

Why don’t you open a new ticket instead of commenting on one that’s been closed and released.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found