Class JsonApiResource

java.lang.Object
org.apache.juneau.bean.jsonapi.JsonApiResource

@Marshalled public class JsonApiResource extends Object
Represents a JSON:API Resource Object as defined by JSON:API v1.1 § Resource Objects.

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 Details

    • JsonApiResource

      public JsonApiResource()
      Default constructor.
    • JsonApiResource

      public JsonApiResource(String type, String id)
      Convenience constructor.
      Parameters:
      type - The entity-type name. Can be null to leave the property unset.
      id - The identifier value. Can be null to leave the property unset.
  • Method Details

    • getType

      public String getType()
      Bean property getter: type.

      Plain String entity-type name. See class-level Javadoc for why this is not a Juneau polymorphic discriminator.

      Returns:
      The value of the type property, or null if it is not set.
    • setType

      public JsonApiResource setType(String value)
      Bean property setter: type.
      Parameters:
      value - The new value for this property. Can be null to unset the property.
      Returns:
      This object.
    • getId

      public String getId()
      Bean property getter: id.
      Returns:
      The value of the id property, or null if it is not set.
    • setId

      public JsonApiResource setId(String value)
      Bean property setter: id.
      Parameters:
      value - The new value for this property. Can be null to unset the property.
      Returns:
      This object.
    • getAttributes

      Bean property getter: attributes.

      The spec lets attributes be any JSON object. Modeled as Map<String,Object> (a nested object on the wire — not flattened).

      Returns:
      The value of the attributes property, or null if it is not set.
    • setAttributes

      Bean property setter: attributes.
      Parameters:
      value - The new value for this property. Can be null to unset the property.
      Returns:
      This object.
    • putAttribute

      public JsonApiResource putAttribute(String name, Object value)
      Convenience method to add a single attribute.
      Parameters:
      name - The attribute name. Can be null (LinkedHashMap tolerates a null key).
      value - The attribute value. Can be null (stored as null).
      Returns:
      This object.
    • getRelationships

      Bean property getter: relationships.
      Returns:
      The value of the relationships property, or null if it is not set.
    • setRelationships

      Bean property setter: relationships.
      Parameters:
      value - The new value for this property. Can be null to unset the property.
      Returns:
      This object.
    • putRelationship

      Convenience method to add a single named relationship.
      Parameters:
      name - The relationship name. Can be null (LinkedHashMap tolerates a null key).
      value - The relationship object. Can be null (stored as null).
      Returns:
      This object.
    • getLinks

      Bean property getter: links.

      Per spec, each links value can be either a JSON string URL or a JsonApiLink object.

      Returns:
      The value of the links property, or null if it is not set.
    • setLinks

      Bean property setter: links.
      Parameters:
      value - The new value for this property. Can be null to unset the property.
      Returns:
      This object.
    • putLink

      public JsonApiResource putLink(String name, Object value)
      Convenience method to add a single link.
      Parameters:
      name - The link name. Can be null (LinkedHashMap tolerates a null key).
      value - The link value (a String URL or a JsonApiLink object). Can be null (stored as null).
      Returns:
      This object.
    • getMeta

      public Map<String,Object> getMeta()
      Bean property getter: meta.
      Returns:
      The value of the meta property, or null if it is not set.
    • setMeta

      Bean property setter: meta.
      Parameters:
      value - The new value for this property. Can be null to unset the property.
      Returns:
      This object.
    • putMeta

      public JsonApiResource putMeta(String name, Object value)
      Convenience method to add a single meta entry.
      Parameters:
      name - The meta key. Can be null (LinkedHashMap tolerates a null key).
      value - The meta value. Can be null (stored as null).
      Returns:
      This object.
    • toString

      public String toString()
      Overrides:
      toString in class Object