Package org.sdase.commons.server.jackson
Class EmbedHelper
- java.lang.Object
-
- org.sdase.commons.server.jackson.EmbedHelper
-
- All Implemented Interfaces:
javax.ws.rs.core.Feature
public class EmbedHelper extends java.lang.Object implements javax.ws.rs.core.Feature
Helper utility that can be registered in the Jersey environment to be injected into services. It supports checking if the client requested to embed a linked resource. Usage:if (embedHelper.isEmbeddingOfRelationRequested("owner")) { carResource.setOwner(createPerson(ownerId)); }
Clients may request to resolve a link as an embedded resource by appending the query param
embed
to the request uri containing all the named relations they want to embed.embed
may be be added multiple times to create an array of relation names or contain multiple relation names separated by comma, e.g.:GET /api/cars?embed=drivers&embed=owner
GET /api/cars?embed=drivers,owner
-
-
Constructor Summary
Constructors Constructor Description EmbedHelper(io.dropwizard.setup.Environment environment)
Create a new embed helper instance and register it in the givenenvironment
so that it becomesContext
aware.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
configure(javax.ws.rs.core.FeatureContext context)
boolean
isEmbeddingOfRelationRequested(java.lang.String relationName)
-
-
-
Method Detail
-
isEmbeddingOfRelationRequested
public boolean isEmbeddingOfRelationRequested(java.lang.String relationName)
- Parameters:
relationName
- the name of the relation, e.g.project
in @{code { "_links": {"project": {"href": "http..."}}}}- Returns:
- if the client requested to embed the resource referenced in the link with the given relation name
-
configure
public boolean configure(javax.ws.rs.core.FeatureContext context)
- Specified by:
configure
in interfacejavax.ws.rs.core.Feature
-
-