Class HalResource
A HAL Resource carries three pieces of state:
- The reserved
_linksmember - a map of relation name to either a singleHalLinkor aHalLinkArray. - The reserved
_embeddedmember - a map of relation name to either a singleHalResourceor aHalResourceArray(sub-resources). HAL embeddings are conceptually a tree; cyclic_embeddedgraphs are rejected by Juneau'sBeanTraverseContextby default. - Arbitrary payload fields, set via the dynamic
set(String,Object)method (uses the@BeanProp("*")extra-properties triplet, the same pattern used byOpenApiElementandSwaggerElement).
Example:
HalResource
See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddEmbedded(String relation, HalResource value) Convenience method that embeds a single sub-resource under the given relation.addEmbedded(String relation, HalResource... values) Convenience method that appends one or more sub-resources to aHalResourceArraystored underrelation.Convenience method that adds a single link under the given relation.Convenience method that appends one or more links to aHalLinkArraystored underrelation.Generic property keyset.Generic property getter.Bean property getter:_embedded .getLinks()Bean property getter:_links .Generic property setter.setEmbedded(Map<String, Object> value) Bean property setter:_embedded .Bean property setter:_links .toString()
-
Constructor Details
-
HalResource
public HalResource()Default constructor.
-
-
Method Details
-
getLinks
Bean property getter:_links .The reserved
_linksmember. Each map value is either a singleHalLink(rendered as a JSON object on the wire) or aHalLinkArray(rendered as a JSON array).- Returns:
- The value of the
_links property, ornull if it is not set.
-
setLinks
@BeanProp("_links") @Swap(HalLinkOrArraySwap.class) public HalResource setLinks(Map<String, Object> value) Bean property setter:_links .- Parameters:
value- The new value for this property. Can benull to unset.- Returns:
- This object.
-
addLink
Convenience method that adds a single link under the given relation.If a value already exists for
relation, it is replaced with the supplied single link. To accumulate multiple links under the same relation useaddLinks(String, HalLink...)instead.- Parameters:
relation- The link relation (e.g."self","next","curies"). Must not benull , or anIllegalArgumentExceptionis thrown.value- The link to set. Can benull (stored as anull entry under the relation).- Returns:
- This object.
-
addLinks
Convenience method that appends one or more links to aHalLinkArraystored underrelation.If the current value at
relationis a singleHalLink, it is promoted to aHalLinkArraycontaining the original link and the appended ones.- Parameters:
relation- The link relation. Must not benull , or anIllegalArgumentExceptionis thrown.values- The links to append.- Returns:
- This object.
-
getEmbedded
Bean property getter:_embedded .The reserved
_embeddedmember. Each map value is either a singleHalResourceor aHalResourceArray.- Returns:
- The value of the
_embedded property, ornull if it is not set.
-
setEmbedded
@BeanProp("_embedded") @Swap(HalResourceOrArraySwap.class) public HalResource setEmbedded(Map<String, Object> value) Bean property setter:_embedded .Note: HAL embeddings are conceptually a tree, not a graph. Juneau's
BeanTraverseContextthrows on cyclic references by default, which matches the spec.- Parameters:
value- The new value for this property. Can benull to unset.- Returns:
- This object.
-
addEmbedded
Convenience method that embeds a single sub-resource under the given relation.- Parameters:
relation- The relation name. Must not benull , or anIllegalArgumentExceptionis thrown.value- The sub-resource. Can benull (stored as anull entry under the relation).- Returns:
- This object.
-
addEmbedded
Convenience method that appends one or more sub-resources to aHalResourceArraystored underrelation.- Parameters:
relation- The relation name. Must not benull , or anIllegalArgumentExceptionis thrown.values- The sub-resources to append.- Returns:
- This object.
-
extraKeys
Generic property keyset.- Returns:
- All the payload (non-
_links, non-_embedded) property names on this resource. Nevernull .
-
get
Generic property getter.- Parameters:
property- The property name. Must not benull , or anIllegalArgumentExceptionis thrown.- Returns:
- The property value, or
null if the property is not set.
-
set
Generic property setter.Use this to set arbitrary payload fields alongside
_linksand_embedded.- Parameters:
property- The property name. Must not benull , or anIllegalArgumentExceptionis thrown.value- The new value for the property. Can benull (stored asnull ).- Returns:
- This object.
-
toString
-