Class JsonApiResource
Carries the standard six members: type, id, attributes, relationships,
links, meta.
Why type is a plain String
JSON:API uses type as an open-ended string field on resource objects (the entity-type name, e.g.
"articles"); the value is chosen by the API and is not a closed Java class hierarchy.
Juneau's @Marshalled(typePropertyName=...) discriminator defaults to _type (so there is also
no literal name clash). Do NOT annotate JsonApiResource with
@Marshalled(typePropertyName="type", dictionary=...) — that would conflate JSON:API resource typing
with Juneau bean dispatch, break round-tripping of unknown type values, and force every API to
enumerate its resource types in a Java dictionary up front.
See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.JsonApiResource(String type, String id) Convenience constructor. -
Method Summary
Modifier and TypeMethodDescriptionBean property getter:attributes .getId()Bean property getter:id .getLinks()Bean property getter:links .getMeta()Bean property getter:meta .Bean property getter:relationships .getType()Bean property getter:type .putAttribute(String name, Object value) Convenience method to add a single attribute.Convenience method to add a single link.Convenience method to add a single meta entry.putRelationship(String name, JsonApiRelationship value) Convenience method to add a single named relationship.setAttributes(Map<String, Object> value) Bean property setter:attributes .Bean property setter:id .Bean property setter:links .Bean property setter:meta .setRelationships(Map<String, JsonApiRelationship> value) Bean property setter:relationships .Bean property setter:type .toString()
-
Constructor Details
-
JsonApiResource
public JsonApiResource()Default constructor. -
JsonApiResource
Convenience constructor.- Parameters:
type- The entity-type name. Can benull to leave the property unset.id- The identifier value. Can benull to leave the property unset.
-
-
Method Details
-
getType
Bean property getter:type .Plain
Stringentity-type name. See class-level Javadoc for why this is not a Juneau polymorphic discriminator.- Returns:
- The value of the
type property, ornull if it is not set.
-
setType
Bean property setter:type .- Parameters:
value- The new value for this property. Can benull to unset the property.- Returns:
- This object.
-
getId
Bean property getter:id .- Returns:
- The value of the
id property, ornull if it is not set.
-
setId
Bean property setter:id .- Parameters:
value- The new value for this property. Can benull to unset the property.- Returns:
- This object.
-
getAttributes
Bean property getter:attributes .The spec lets
attributesbe any JSON object. Modeled asMap<String,Object>(a nested object on the wire — not flattened).- Returns:
- The value of the
attributes property, ornull if it is not set.
-
setAttributes
Bean property setter:attributes .- Parameters:
value- The new value for this property. Can benull to unset the property.- Returns:
- This object.
-
putAttribute
Convenience method to add a single attribute.- Parameters:
name- The attribute name. Can benull (LinkedHashMaptolerates anull key).value- The attribute value. Can benull (stored asnull ).- Returns:
- This object.
-
getRelationships
Bean property getter:relationships .- Returns:
- The value of the
relationships property, ornull if it is not set.
-
setRelationships
Bean property setter:relationships .- Parameters:
value- The new value for this property. Can benull to unset the property.- Returns:
- This object.
-
putRelationship
Convenience method to add a single named relationship.- Parameters:
name- The relationship name. Can benull (LinkedHashMaptolerates anull key).value- The relationship object. Can benull (stored asnull ).- Returns:
- This object.
-
getLinks
Bean property getter:links .Per spec, each
linksvalue can be either a JSON string URL or aJsonApiLinkobject.- Returns:
- The value of the
links property, ornull if it is not set.
-
setLinks
@BeanProp("links") @Swap(JsonApiLinkOrStringSwap.class) public JsonApiResource setLinks(Map<String, Object> value) Bean property setter:links .- Parameters:
value- The new value for this property. Can benull to unset the property.- Returns:
- This object.
-
putLink
Convenience method to add a single link.- Parameters:
name- The link name. Can benull (LinkedHashMaptolerates anull key).value- The link value (aStringURL or aJsonApiLinkobject). Can benull (stored asnull ).- Returns:
- This object.
-
getMeta
Bean property getter:meta .- Returns:
- The value of the
meta property, ornull if it is not set.
-
setMeta
Bean property setter:meta .- Parameters:
value- The new value for this property. Can benull to unset the property.- Returns:
- This object.
-
putMeta
Convenience method to add a single meta entry.- Parameters:
name- The meta key. Can benull (LinkedHashMaptolerates anull key).value- The meta value. Can benull (stored asnull ).- Returns:
- This object.
-
toString
-