Skip to content
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

Traverson cannot follow multiple links with same rel #768

Open
asgeirn opened this issue Dec 14, 2018 · 6 comments
Open

Traverson cannot follow multiple links with same rel #768

asgeirn opened this issue Dec 14, 2018 · 6 comments

Comments

@asgeirn
Copy link

asgeirn commented Dec 14, 2018

Similar to traverson/traverson#7, TraversalBuilder cannot follow multiple links from a resource having the same rel value:

{
    "_links": {
        "parorende": [{
                "href": "https://play-with-fint.felleskomponent.no/utdanning/elev/kontaktperson/systemid/XXXXXX"
            },
            {
                "href": "https://play-with-fint.felleskomponent.no/utdanning/elev/kontaktperson/systemid/YYYYYY"
            }
        ],
        "self": [{
            "href": "https://play-with-fint.felleskomponent.no/utdanning/elev/person/fodselsnummer/02040754515"
        }]
    }
}
@gregturn
Copy link
Contributor

Intriguing problem.

What would you propose as the how the API should look to handle this?

@asgeirn
Copy link
Author

asgeirn commented Dec 17, 2018

There are discussions over at traverson/traverson-hal#7, but the feature hasn't fully landed in traverson just yet.

I would suggest an API that leverages java.util.Stream, perhaps using method signatures like

Stream<T> toObjects(Class<T> cls)

The tricky part is if an intermediate link in the traversal chain is plural, as this means the traversal process needs to be recursive in able to resume traversal at an earlier stage after completing one path.

This could for instance be indicated using .follow("rel[]") or .follow("rel[$all]") as in traverson.

@gregturn
Copy link
Contributor

Frankly I don’t grok a relationship with multiple links. How do you present that to the user?

Multiple rels, I get. But not the other way around.

@schauder
Copy link
Contributor

I guess one could have a button/link that tries the first and if that fails tries the next.

@asgeirn
Copy link
Author

asgeirn commented Dec 17, 2018

What we're trying to express is in fact multiple links, to different resources, of the same relation. The data in the example above attempts to express next of kin, in this concrete example parents, but it does not have to be parents in the traditional interpretation. In a modern world, parents are no longer exactly two individuals of opposite gender, hence the requirement for a more general way of expressing relationships.

Quoting from http://stateless.co/hal_specification.html:

Representing Multiple Links With The Same Relation

A resource may have multiple links that share the same link relation.

For link relations that may have multiple links, we use an array of links.

 {
      "_links": {
       "items": [{
           "href": "/first_item"
       },{
           "href": "/second_item"
       }]
     }
 }

Note: If you're unsure whether the link should be singular, assume it will be multiple. If you pick singular and find you need to change it, you will need to create a new link relation or face breaking existing clients.

@gregturn
Copy link
Contributor

gregturn commented Mar 6, 2019

Okay I’ve seen recent hypermedia showing multiple links tied to one link relation.

Sounds like Traverson would need a strategy like FIRST, RANDOM, FAILOVER, ???

What do you think?

odrotbohm added a commit that referenced this issue Jan 13, 2020
Problem has been redesigned for immutability. Extensions to the payload body are now implemented by wrapping a either an object exposing the properties to add in turn or a plain Map.

Added infrastructure configuration to make sure that Problem instances returned from controller methods (even if wrapped into a ResponseEntity<?>) cause the ContentType header to be set to application/problem+json. HyperMediaMappingInformation now allows to customize the root domain type to signal serialization support for.

Few cleanups regarding the ObjectMapper setup in test cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants