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
RepresentationModelAssembler
s. Will automate RepresentationModel
instance
creation and make sure a self-link is always added.- Author:
- Oliver Gierke, Greg Turnquist
-
Constructor Summary
ConstructorDescriptionRepresentationModelAssemblerSupport
(Class<?> controllerClass, Class<D> resourceType) Creates a newRepresentationModelAssemblerSupport
using the given controller class and resource type. -
Method Summary
Modifier and TypeMethodDescriptionprotected D
createModelWithId
(Object id, T entity) Creates a new resource with a self link to the given id.protected D
createModelWithId
(Object id, T entity, Object... parameters) protected Class<?>
protected D
instantiateModel
(T entity) Instantiates the resource object.Maps the givenIterable
of entities to either aCollectionModel
or simple List ofRepresentationModel
s.toCollectionModel
(Iterable<? extends T> entities) Converts anIterable
orT
s into anIterable
ofRepresentationModel
and wraps them in aCollectionModel
instance.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.hateoas.server.RepresentationModelAssembler
toModel
-
Constructor Details
-
RepresentationModelAssemblerSupport
Creates a newRepresentationModelAssemblerSupport
using the given controller class and resource type.- Parameters:
controllerClass
- must not be null.resourceType
- must not be null.
-
-
Method Details
-
toCollectionModel
Description copied from interface:RepresentationModelAssembler
Converts anIterable
orT
s into anIterable
ofRepresentationModel
and wraps them in aCollectionModel
instance.- Specified by:
toCollectionModel
in interfaceRepresentationModelAssembler<T,
D extends RepresentationModel<?>> - Parameters:
entities
- must not be null.- Returns:
CollectionModel
containingD
.
-
map
public org.springframework.hateoas.server.mvc.RepresentationModelAssemblerSupport.Builder<T,D> map(Iterable<? extends T> entities) Maps the givenIterable
of entities to either aCollectionModel
or simple List ofRepresentationModel
s.- Parameters:
entities
- must not be null.- Returns:
-
createModelWithId
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
-
getControllerClass
-
getResourceType
-
instantiateModel
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:
-