Class JsonApiResourceMapper
ResourceObject instances and documents.
Construct instances via JsonApiJackson3.resourceMapper(tools.jackson.databind.json.JsonMapper) or its overloads, never
directly. The mapper is safe for concurrent use once created. Decorators supplied through a
ResourceDecoratorRegistry are invoked during mapping and may
be called concurrently; they must themselves be safe for concurrent invocation when the mapper is
shared. Mapping uses Jackson's logical property model and caches resolved definitions by type and
configuration identity. JSON:API annotations assign semantic roles; configured Jackson owns
property discovery, visibility, external naming, mix-ins, creators, and value conversion.
Unannotated Jackson-visible properties do not participate, except the conventional identifier
whose Jackson external name is id. @JsonApiId maps only ResourceObject.id() and @JsonApiLocalId maps only ResourceObject.lid(); the two
identity roles never fall back to each other.
Mapping is write-only: this mapper produces core model objects. Feed them to a JsonApiDocumentWriter for serialization. Read-side flat DTO binding is provided by JsonApiResourceBinder.
The convenience methods infer a root JavaType from the concrete runtime class. Use the
overloads that accept a JavaType for a directly parameterized root such as
Container<Thing>; the declared type is retained through mapping, relationship linkage, and
compound inclusion. Concrete subclasses that bind a generic superclass can use the convenience
methods when Jackson resolves those bindings. An unparameterized generic root fails at the mapped
member that requires the missing declaration rather than inferring a type from runtime contents.
Compound inclusion is opt-in via RepresentationSelection and RepresentationPolicy on the mapper overloads that accept representation inputs. Relationship
mapping alone never requests inclusion. Callers without an envelope pass null for the
envelope argument.
Sparse fieldsets are applied only by toMappedDocument(Object, DocumentEnvelope, RepresentationSelection, RepresentationPolicy) and toMappedCollectionDocument(Iterable, DocumentEnvelope, RepresentationSelection, RepresentationPolicy). Those overloads return a
MappedDocument carrying the identities of included resources whose inbound linkage was
removed by an applied fieldset; a document writer composes that provenance into validation. The
non-mapped representation overloads (with or without a declared JavaType) reject a
non-empty fieldset map with MappingDiagnostic.FIELDSETS_REQUIRE_MAPPED_DOCUMENT.
For custom identifier conversion, supply an IdentifierConverter at construction time.
The default converter delegates to Object.toString().
-
Method Summary
Modifier and TypeMethodDescriptioncom.kazforge.jsonapi.core.model.JsonApiDocumenttoCollectionDocument(Iterable<?> resources) Maps domain objects to a resource-collection document without envelope members.com.kazforge.jsonapi.core.model.JsonApiDocumenttoCollectionDocument(Iterable<?> resources, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope) Maps domain objects to a resource-collection document with optional envelope members.com.kazforge.jsonapi.core.model.JsonApiDocumenttoCollectionDocument(Iterable<?> resources, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a primary collection to a document with optional envelope members and explicit compound inclusion fromselectiongoverned bypolicy.com.kazforge.jsonapi.core.model.JsonApiDocumenttoCollectionDocument(Iterable<?> resources, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope) Maps a homogeneous collection using a complete declared element type and optional envelope.com.kazforge.jsonapi.core.model.JsonApiDocumenttoCollectionDocument(Iterable<?> resources, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a homogeneous collection with explicit compound inclusion using the complete declared element type supplied by the caller.com.kazforge.jsonapi.core.model.JsonApiDocumenttoDocument(Object resource) Maps a domain object to a single-resource document without envelope members.com.kazforge.jsonapi.core.model.JsonApiDocumenttoDocument(Object resource, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope) Maps a domain object to a single-resource document with optional envelope members.com.kazforge.jsonapi.core.model.JsonApiDocumenttoDocument(Object resource, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object to a document with optional envelope members and explicit compound inclusion fromselectiongoverned bypolicy.com.kazforge.jsonapi.core.model.JsonApiDocumenttoDocument(Object resource, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope) Maps a domain object to a document using a complete declared type and optional envelope.com.kazforge.jsonapi.core.model.JsonApiDocumenttoDocument(Object resource, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object to a document with explicit inclusion using the complete declared Jackson type supplied by the caller.com.kazforge.jsonapi.mapping.MappedDocumenttoMappedCollectionDocument(Iterable<?> resources, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a primary collection with optional envelope members, compound inclusion, and sparse fieldsets fromselectiongoverned bypolicy.com.kazforge.jsonapi.mapping.MappedDocumenttoMappedCollectionDocument(Iterable<?> resources, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a homogeneous collection with inclusion and sparse fieldsets using a complete declared type.com.kazforge.jsonapi.mapping.MappedDocumenttoMappedCreateDocument(Object resource, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object for create-request authoring with optional envelope members, compound inclusion, and sparse fieldsets fromselectiongoverned bypolicy.com.kazforge.jsonapi.mapping.MappedDocumenttoMappedCreateDocument(Object resource, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object for create-request authoring using a complete declared type.com.kazforge.jsonapi.mapping.MappedDocumenttoMappedDocument(Object resource, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object with optional envelope members, compound inclusion, and sparse fieldsets fromselectiongoverned bypolicy.com.kazforge.jsonapi.mapping.MappedDocumenttoMappedDocument(Object resource, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object with inclusion and sparse fieldsets using a complete declared type.com.kazforge.jsonapi.core.model.ResourceObjecttoResource(Object resource) Maps a domain object using a Jackson type inferred from its concrete runtime class.com.kazforge.jsonapi.core.model.ResourceObjecttoResource(Object resource, tools.jackson.databind.JavaType resourceType) Maps a domain object using the complete declared Jackson type supplied by the caller.
-
Method Details
-
toResource
Maps a domain object using a Jackson type inferred from its concrete runtime class. -
toResource
public com.kazforge.jsonapi.core.model.ResourceObject toResource(Object resource, tools.jackson.databind.JavaType resourceType) Maps a domain object using the complete declared Jackson type supplied by the caller. -
toDocument
Maps a domain object to a single-resource document without envelope members. -
toDocument
public com.kazforge.jsonapi.core.model.JsonApiDocument toDocument(Object resource, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope) Maps a domain object to a single-resource document with optional envelope members. -
toDocument
public com.kazforge.jsonapi.core.model.JsonApiDocument toDocument(Object resource, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope) Maps a domain object to a document using a complete declared type and optional envelope. -
toDocument
public com.kazforge.jsonapi.core.model.JsonApiDocument toDocument(Object resource, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object to a document with optional envelope members and explicit compound inclusion fromselectiongoverned bypolicy. Rejects a non-empty fieldset map; usetoMappedDocument(java.lang.Object, com.kazforge.jsonapi.document.DocumentEnvelope, com.kazforge.jsonapi.representation.RepresentationSelection, com.kazforge.jsonapi.representation.RepresentationPolicy)when applying sparse fieldsets. -
toDocument
public com.kazforge.jsonapi.core.model.JsonApiDocument toDocument(Object resource, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object to a document with explicit inclusion using the complete declared Jackson type supplied by the caller. -
toMappedDocument
public com.kazforge.jsonapi.mapping.MappedDocument toMappedDocument(Object resource, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object with optional envelope members, compound inclusion, and sparse fieldsets fromselectiongoverned bypolicy. Returns aMappedDocumentwhose linkage exemptions name included resources whose linking relationship was omitted by an applied fieldset while inclusion still traversed it. -
toMappedDocument
public com.kazforge.jsonapi.mapping.MappedDocument toMappedDocument(Object resource, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object with inclusion and sparse fieldsets using a complete declared type. -
toMappedCreateDocument
public com.kazforge.jsonapi.mapping.MappedDocument toMappedCreateDocument(Object resource, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object for create-request authoring with optional envelope members, compound inclusion, and sparse fieldsets fromselectiongoverned bypolicy. UnliketoMappedDocument(java.lang.Object, com.kazforge.jsonapi.document.DocumentEnvelope, com.kazforge.jsonapi.representation.RepresentationSelection, com.kazforge.jsonapi.representation.RepresentationPolicy), a primary resource with neitheridnorlidvalue maps with both members absent instead of failing; coreCREATE_REQUESTvalidation owns that leniency when the document is written. Compound inclusion likewise traverses an identity-less primary while included resources still require identity, and related linkage uses normal extraction. Returns aMappedDocumentcarrying sparse-fieldset linkage provenance liketoMappedDocument(java.lang.Object, com.kazforge.jsonapi.document.DocumentEnvelope, com.kazforge.jsonapi.representation.RepresentationSelection, com.kazforge.jsonapi.representation.RepresentationPolicy). -
toMappedCreateDocument
public com.kazforge.jsonapi.mapping.MappedDocument toMappedCreateDocument(Object resource, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a domain object for create-request authoring using a complete declared type. -
toCollectionDocument
Maps domain objects to a resource-collection document without envelope members. -
toCollectionDocument
public com.kazforge.jsonapi.core.model.JsonApiDocument toCollectionDocument(Iterable<?> resources, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope) Maps domain objects to a resource-collection document with optional envelope members. -
toCollectionDocument
public com.kazforge.jsonapi.core.model.JsonApiDocument toCollectionDocument(Iterable<?> resources, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope) Maps a homogeneous collection using a complete declared element type and optional envelope. -
toCollectionDocument
public com.kazforge.jsonapi.core.model.JsonApiDocument toCollectionDocument(Iterable<?> resources, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a primary collection to a document with optional envelope members and explicit compound inclusion fromselectiongoverned bypolicy. The iterable is materialized once and reused for type validation, primary mapping, and inclusion traversal. Rejects a non-empty fieldset map; usetoMappedCollectionDocument(java.lang.Iterable<?>, com.kazforge.jsonapi.document.DocumentEnvelope, com.kazforge.jsonapi.representation.RepresentationSelection, com.kazforge.jsonapi.representation.RepresentationPolicy)when applying sparse fieldsets. -
toCollectionDocument
public com.kazforge.jsonapi.core.model.JsonApiDocument toCollectionDocument(Iterable<?> resources, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a homogeneous collection with explicit compound inclusion using the complete declared element type supplied by the caller. -
toMappedCollectionDocument
public com.kazforge.jsonapi.mapping.MappedDocument toMappedCollectionDocument(Iterable<?> resources, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a primary collection with optional envelope members, compound inclusion, and sparse fieldsets fromselectiongoverned bypolicy. The iterable is materialized once. Returns aMappedDocumentwhose linkage exemptions fold fieldset-removed linking relationships across primary and included selective writes. -
toMappedCollectionDocument
public com.kazforge.jsonapi.mapping.MappedDocument toMappedCollectionDocument(Iterable<?> resources, tools.jackson.databind.JavaType resourceType, @Nullable com.kazforge.jsonapi.document.DocumentEnvelope envelope, com.kazforge.jsonapi.representation.RepresentationSelection selection, com.kazforge.jsonapi.representation.RepresentationPolicy policy) Maps a homogeneous collection with inclusion and sparse fieldsets using a complete declared type.
-