Class EmbedHelper

java.lang.Object
org.sdase.commons.server.jackson.EmbedHelper
All Implemented Interfaces:
jakarta.ws.rs.core.Feature

public class EmbedHelper extends Object implements 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 Details

    • EmbedHelper

      public EmbedHelper(io.dropwizard.core.setup.Environment environment)
      Create a new embed helper instance and register it in the given environment so that it becomes Context aware.
      Parameters:
      environment - The Dropwizard environment to register this instance in.
  • Method Details

    • isEmbeddingOfRelationRequested

      public boolean isEmbeddingOfRelationRequested(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(jakarta.ws.rs.core.FeatureContext context)
      Specified by:
      configure in interface jakarta.ws.rs.core.Feature