Skip to content

ResourceSupport might benefit from having a method that returns a list of links that have the same rel. #318

Closed
@vivin

Description

@vivin

Currently there is a method called getLink(String rel) that returns a link with the given rel. However, it is possible to have multiple links that share the same rel. Therefore, I think it might be beneficial to have a method like so:

public List<Link> getLinks(String rel);

Which will return a list of links that have the given rel.

Activity

added a commit that references this issue on Mar 16, 2015
chrylis

chrylis commented on Mar 21, 2015

@chrylis
vivin

vivin commented on Mar 21, 2015

@vivin
Author

Ahh thanks! I did not see the original issue. @olivergierke thoughts about this?

chrylis

chrylis commented on Mar 22, 2015

@chrylis

That's not a 100% duplicate, but I think we're looking at the same issue. Essentially, the current getLink (1) returns a single value and (2) doesn't play nicely with the map-navigation syntax offered by Groovy and *EL. What I'd prefer to see in place of your signature is

Map<String, Collection<Link>> getLinks();

That way, something like myobj.links['picture'].href would work.

vivin

vivin commented on Mar 22, 2015

@vivin
Author

I think changing the signature of the existing one would be a breaking change, unfortunately. The new method I suggested would sort of do what you want, except instead of working with a map directly, you're asking the ResourceSupport class to filter out links with the rel you want. The performance would be lacking since it would be O(n) since you have to traverse the entire list. I think that could be mitigated if the internal representation is modified from List<T> into Map<K, V>.

chrylis

chrylis commented on Mar 23, 2015

@chrylis

It absolutely would be a breaking change, but we're still at major version 0. (I note additionally that HAL seems to specify that link rels are unique per entity, which means that the current list-based implementation is also problematic in permitting duplicates.) Changing the internal representation is what I recommended a while back, but I haven't heard any comments.

dschulten

dschulten commented on Mar 23, 2015

@dschulten
Contributor

Hi,

although I find it problematic, too, to use duplicates, HAL specifically
allows them in section 4.1.1 where it says that the value of the rel may be
an array of link objects. It uses this feature explicitly for curies.

Best,
Dietrich

Am 23. März 2015 04:24:11 schrieb Christopher Smith notifications@github.com:

It absolutely would be a breaking change, but we're still at major version
0. (I note additionally that HAL seems to specify that link rels are unique
per entity, which means that the current list-based implementation is also
problematic in permitting duplicates.) Changing the internal representation
is what I recommended a while back, but I haven't heard any comments.


Reply to this email directly or view it on GitHub:
#318 (comment)

chrylis

chrylis commented on Mar 23, 2015

@chrylis

Aha. Well, in that case, something with the semantics of a multimap are probably best.

vivin

vivin commented on Mar 23, 2015

@vivin
Author

Yes, a rel can represent multiple links and HAL does allow that. Internally a Map<String, List<Link>> would make much more sense, I think, but I haven't heard any comments either about this issue (and some others as well).

odrotbohm

odrotbohm commented on May 21, 2015

@odrotbohm
Member

What if we just added List<Link> getLinks(String rel)?

self-assigned this
on May 21, 2015
chrylis

chrylis commented on May 21, 2015

@chrylis

That would be an improvement, but it's still awkward in contexts (Groovy, SpEL) that support map-style syntax.

odrotbohm

odrotbohm commented on May 21, 2015

@odrotbohm
Member

foo.getLinks(…).href?

chrylis

chrylis commented on May 21, 2015

@chrylis

Works okay if you're looking for links for a specific rel (though still more cumbersome than foo.links.picture[0].href, since getLinks isn't a property accessor), but there's no simple way to iterate over rels.

1 remaining item

chrylis

chrylis commented on May 21, 2015

@chrylis

@gregturn I've actually suggested just making the links a Map<String,Link> (or Map<String,Collection<Link>>. The interface makes a lot more sense to me.

vivin

vivin commented on May 21, 2015

@vivin
Author

@olivergierke List<Link> getLinks(String rel) would work. To address @chrylis concerns, perhaps a method Map<String, List<Link>> getLinks() would work.

gregturn

gregturn commented on Mar 26, 2017

@gregturn
Contributor

Related to #542

added a commit that references this issue on Mar 26, 2017
added 2 commits that reference this issue on Mar 26, 2017

#566 - Return list of links for a given rel

25cd099

#566 - Return list of links for a given rel

84e4ed7
added a commit that references this issue on Mar 26, 2017

#566 - Return list of links for a given rel

0e8b0e1
gregturn

gregturn commented on Mar 26, 2017

@gregturn
Contributor

Resolved via 0e8b0e1

added this to the 0.24 milestone on Mar 26, 2017
added a commit that references this issue on Mar 26, 2017

#566 - Introduced ResourceSupport.getLinks(…) to return all with a gi…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @vivin@dschulten@odrotbohm@gregturn@chrylis

      Issue actions

        ResourceSupport might benefit from having a method that returns a list of links that have the same rel. · Issue #318 · spring-projects/spring-hateoas