Class RepresentationModelAssemblerSupport<T,D extends RepresentationModel<?>>

java.lang.Object
org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport<T,D>
All Implemented Interfaces:
RepresentationModelAssembler<T,D>

public abstract class RepresentationModelAssemblerSupport<T,D extends RepresentationModel<?>> extends Object implements RepresentationModelAssembler<T,D>
Base class to implement RepresentationModelAssemblers. Will automate RepresentationModel instance creation and make sure a self-link is always added.
Author:
Oliver Gierke, Greg Turnquist
  • Constructor Details

    • RepresentationModelAssemblerSupport

      public RepresentationModelAssemblerSupport(Class<?> controllerClass, Class<D> resourceType)
      Creates a new RepresentationModelAssemblerSupport using the given controller class and resource type.
      Parameters:
      controllerClass - must not be null.
      resourceType - must not be null.
  • Method Details

    • toCollectionModel

      public CollectionModel<D> toCollectionModel(Iterable<? extends T> entities)
      Description copied from interface: RepresentationModelAssembler
      Converts an Iterable or Ts into an Iterable of RepresentationModel and wraps them in a CollectionModel instance.
      Specified by:
      toCollectionModel in interface RepresentationModelAssembler<T,D extends RepresentationModel<?>>
      Parameters:
      entities - must not be null.
      Returns:
      CollectionModel containing D.
    • map

      public org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport.Builder<T,D> map(Iterable<? extends T> entities)
      Maps the given Iterable of entities to either a CollectionModel or simple List of RepresentationModels.
      Parameters:
      entities - must not be null.
      Returns:
    • createModelWithId

      protected D createModelWithId(Object id, T entity)
      Creates a new resource with a self link to the given id.
      Parameters:
      entity - must not be null.
      id - must not be null.
      Returns:
    • createModelWithId

      protected D createModelWithId(Object id, T entity, Object... parameters)
    • getControllerClass

      protected Class<?> getControllerClass()
    • getResourceType

      protected Class<D> getResourceType()
    • instantiateModel

      protected D instantiateModel(T entity)
      Instantiates the resource object. Default implementation will assume a no-arg constructor and use reflection but can be overridden to manually set up the object instance initially (e.g. to improve performance if this becomes an issue).
      Parameters:
      entity -
      Returns: