Package org.sdase.commons.server.jackson
Class EmbedHelper
java.lang.Object
org.sdase.commons.server.jackson.EmbedHelper
- All Implemented Interfaces:
jakarta.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
ConstructorDescriptionEmbedHelper
(io.dropwizard.core.setup.Environment environment) Create a new embed helper instance and register it in the givenenvironment
so that it becomesContext
aware. -
Method Summary
Modifier and TypeMethodDescriptionboolean
configure
(jakarta.ws.rs.core.FeatureContext context) boolean
isEmbeddingOfRelationRequested
(String relationName)
-
Constructor Details
-
EmbedHelper
public EmbedHelper(io.dropwizard.core.setup.Environment environment) Create a new embed helper instance and register it in the givenenvironment
so that it becomesContext
aware.- Parameters:
environment
- The Dropwizard environment to register this instance in.
-
-
Method Details
-
isEmbeddingOfRelationRequested
- 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(jakarta.ws.rs.core.FeatureContext context) - Specified by:
configure
in interfacejakarta.ws.rs.core.Feature
-