Closed mg-2014 closed 6 years ago
Only the rel of the last link is actually added to the previously existing rels. The reason seems to be that rels.put() actually returns a new tree on which the rel is added.
rels.put()
Thus the following code
final TreeMap<String, Rel> updatedRels = links .map(Links::getRel) .foldLeft( rels, (accum, rel) -> !accum.containsKey(rel) ? rels.put(rel, Rels.natural(rel)) : rels);
should rather be:
final TreeMap<String, Rel> updatedRels = links .map(Links::getRel) .foldLeft( rels, (accum, rel) -> !accum.containsKey(rel) ? accum.put(rel, Rels.natural(rel)) : accum);
The issue can be verified by:
ResourceRepresentation<HashMap<Object, Object>> withLinks = ResourceRepresentation.create("/self", HashMap.empty()) .withLinks(List.of(Links.create("link1", "/link1"), Links.create("link2", "/link2"))); JsonRepresentationWriter jsonRepresentationWriter = JsonRepresentationWriter.create(); ByteString representation = jsonRepresentationWriter.print(withLinks);
which will throw an exception.
Cheers for that! I'll cut a new release in the morning.
Only the rel of the last link is actually added to the previously existing rels. The reason seems to be that
rels.put()
actually returns a new tree on which the rel is added.Thus the following code
should rather be:
The issue can be verified by:
which will throw an exception.