Example: Load URI template values from the entity
For example, let's consider the previous Book example, and a list of comments: @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) public class Comment { @ParentResource private Book book; @XmlElement private String author; @XmlID @XmlAttribute private String id; @XmlElementRef private RESTServiceDiscovery rest; } Given the previous book store service augmented with comments: @Path("/") @Consumes({"application/xml", "application/json"}) @Produces({"application/xml", "application/json"}) public interface BookStore { @AddLinks @LinkResources({ @LinkResource(value = Book.class, rel = "comments"), @LinkResource(value = Comment.class) }) @GET @Path("book/{id}/comments") public Collection getComments(@PathParam("id") String bookId); @AddLinks @LinkResource @GET @Path("book/{id}/comment/{cid}") public Comment getComment(@PathParam("id") String bookId, @PathParam("cid") String commentId); @LinkResource @POST @Path("book/{id}/comments") public void addComment(@PathParam("id") String bookId, Comment comment); @LinkResource @PUT @Path("book/{id}/comment/{cid}") public void updateComment(@PathParam("id") String bookId, @PathParam("cid") String commentId, Comment comment); @LinkResource(Comment.class) @DELETE @Path("book/{id}/comment/{cid}") public void deleteComment(@PathParam("id") String bookId, @PathParam("cid") String commentId); } Whenever we need to make links for a Book entity, we look up the ID in the Book's @XmlID property. Whenever we make links for Comment entities, we have a list of values taken from the Comment's @XmlID and its @ParentResource: the Book and its @XmlID. For a Comment with id "1" on a Book with title "foo" we will therefore get a list of URI template values of {"foo", "1"}, to be replaced in the URI template, thus obtaining either "/book/foo/comments" or "/book/foo/comment/1".