Is there a way to bind a JAX-RS resource to another resource like in Spring HATEOAS?
Spring has an annotation @ExposesResourceFor
that can link our resource to other resources. Because of this, our Value objects (views) do not know anything about real resources.
Is there a way to do this in JAX-RS? I am using Dropwizard with Jersey and Jackson and all I can see is an annotation @InjectLinks
that I can use on a value object like this:
public class UserGroup {
@JsonProperty
public String name;
@InjectLinks(GroupsResource.class)
public URI myResource;
public UserGroup(String name){
this.name = name;
}
}
But unfortunately my Value objects do not need to know anything about resources, so I am asking if I can make such a link at the resource level - link in spring -hateoas in controllers as mentioned above.
source to share
With, @InjectLinks
you don't need to declare references in your model class. You can create a "wrapper" view class as shown in declarative-linking from Jersey Examples (although this solution is really not at the resource class level as you wish).
Another possible solution (not declarative bindings) is to use the JAX-RS 2.0 class Link
, and programmatically bind (no jersey implementation / annotation links). You can either add links to the response headers , as seen here , or add Link
classes to your model, as shown here (or use a wrapper class for that to avoid intruding on model classes)
Some resources
source to share