public class HalModelBuilder extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
HalModelBuilder.PreviewBuilder |
Modifier and Type | Method and Description |
---|---|
RepresentationModel<?> |
build()
Transform the entities and
Link s into a RepresentationModel . |
HalModelBuilder |
embed(Collection<?> collection) |
HalModelBuilder |
embed(Collection<?> collection,
Class<?> type) |
HalModelBuilder |
embed(Collection<?> collection,
LinkRelation relation)
Embeds the given collection in the
RepresentationModel for the given LinkRelation . |
HalModelBuilder |
embed(Object entity)
Embeds the given entity into the
RepresentationModel . |
HalModelBuilder |
embed(Object entity,
LinkRelation linkRelation)
Embed the entity and associate it with the
LinkRelation . |
static HalModelBuilder |
emptyHalModel()
Creates a new
HalModelBuilder without a primary payload. |
HalModelBuilder |
entity(Object entity)
Embed the entity, but with no relation.
|
static HalModelBuilder |
halModel()
Creates a new
HalModelBuilder . |
static HalModelBuilder |
halModel(EmbeddedWrappers wrappers)
Creates a new
HalModelBuilder using the given EmbeddedWrappers . |
static HalModelBuilder |
halModelOf(Object entity)
Creates a new
HalModelBuilder with the given entity as primary payload. |
HalModelBuilder |
link(Link link)
Add a
Link to the whole thing. |
HalModelBuilder |
link(String href,
LinkRelation relation)
|
HalModelBuilder |
links(Iterable<Link> links)
Adds the given
Link s to the RepresentationModel to be built. |
HalModelBuilder.PreviewBuilder |
preview(Collection<?> collection)
Starts a preview setup for the given
Collection as preview. |
HalModelBuilder.PreviewBuilder |
preview(Collection<?> collection,
Class<?> type)
Starts a preview setup for the given
Collection as preview falling back to the given type if the
Collection is empty. |
HalModelBuilder.PreviewBuilder |
preview(Object entity)
Initiates the setup of a preview given the current payload.
|
public static HalModelBuilder halModel()
HalModelBuilder
.public static HalModelBuilder halModel(EmbeddedWrappers wrappers)
HalModelBuilder
using the given EmbeddedWrappers
.wrappers
- must not be null.public static HalModelBuilder halModelOf(Object entity)
HalModelBuilder
with the given entity as primary payload.entity
- must not be null.public static HalModelBuilder emptyHalModel()
HalModelBuilder
without a primary payload.public HalModelBuilder entity(Object entity)
entity
- public HalModelBuilder embed(Object entity, LinkRelation linkRelation)
LinkRelation
.entity
- must not be null.linkRelation
- must not be null.public HalModelBuilder embed(Object entity)
RepresentationModel
.entity
- must not be null.public HalModelBuilder embed(Collection<?> collection)
public HalModelBuilder embed(Collection<?> collection, Class<?> type)
public HalModelBuilder embed(Collection<?> collection, LinkRelation relation)
RepresentationModel
for the given LinkRelation
. If the
collection is empty nothing will be added to the RepresentationModel
.collection
- must not be null.relation
- must not be null.#embed(Collection, LinkRelation, Class)
public HalModelBuilder.PreviewBuilder preview(Object entity)
EntityPreviewBuilder#forLink(Link)
methods. As an example, the call chain of:
….preview(…).forLink("…", "relation")will result in the link added to the representation and an embedded being registered for the link's relation:
{ "_links" : { "relation" : { … } }, "_embedded" : { "relation" : … } }
entity
- public HalModelBuilder.PreviewBuilder preview(Collection<?> collection)
Collection
as preview.collection
- preview(Object)
public HalModelBuilder.PreviewBuilder preview(Collection<?> collection, Class<?> type)
Collection
as preview falling back to the given type if the
Collection
is empty.collection
- must not be null.type
- must not be null.preview(Object)
public HalModelBuilder link(Link link)
Link
to the whole thing.
NOTE: This adds it to the top level. If you need a link inside an entity, then use the Model.Builder
to
define it as well.link
- must not be null.public HalModelBuilder link(String href, LinkRelation relation)
href
- must not be null.relation
- must not be null.public HalModelBuilder links(Iterable<Link> links)
Link
s to the RepresentationModel
to be built.links
- must not be null.public RepresentationModel<?> build()
Link
s into a RepresentationModel
. If there are embedded entries, add a
preferred media type of MediaTypes.HAL_JSON
and MediaTypes.HAL_FORMS_JSON
.Copyright © 2011–2020 Pivotal, Inc.. All rights reserved.