Closed
Description
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.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
issue spring-projects#318
chrylis commentedon Mar 21, 2015
#157
vivin commentedon Mar 21, 2015
Ahh thanks! I did not see the original issue. @olivergierke thoughts about this?
chrylis commentedon Mar 22, 2015
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 isThat way, something like
myobj.links['picture'].href
would work.vivin commentedon Mar 22, 2015
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 beO(n)
since you have to traverse the entire list. I think that could be mitigated if the internal representation is modified fromList<T>
intoMap<K, V>
.chrylis commentedon Mar 23, 2015
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 commentedon Mar 23, 2015
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:
chrylis commentedon Mar 23, 2015
Aha. Well, in that case, something with the semantics of a multimap are probably best.
vivin commentedon Mar 23, 2015
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 commentedon May 21, 2015
What if we just added
List<Link> getLinks(String rel)
?chrylis commentedon May 21, 2015
That would be an improvement, but it's still awkward in contexts (Groovy, SpEL) that support map-style syntax.
odrotbohm commentedon May 21, 2015
foo.getLinks(…).href
?chrylis commentedon May 21, 2015
Works okay if you're looking for links for a specific rel (though still more cumbersome than
foo.links.picture[0].href
, sincegetLinks
isn't a property accessor), but there's no simple way to iterate over rels.1 remaining item
chrylis commentedon May 21, 2015
@gregturn I've actually suggested just making the links a
Map<String,Link>
(orMap<String,Collection<Link>>
. The interface makes a lot more sense to me.vivin commentedon May 21, 2015
@olivergierke
List<Link> getLinks(String rel)
would work. To address @chrylis concerns, perhaps a methodMap<String, List<Link>> getLinks()
would work.gregturn commentedon Mar 26, 2017
Related to #542
Return list of links for a given rel
#566 - Return list of links for a given rel
#566 - Return list of links for a given rel
#566 - Return list of links for a given rel
gregturn commentedon Mar 26, 2017
Resolved via 0e8b0e1
#566 - Introduced ResourceSupport.getLinks(…) to return all with a gi…