Record Class RelationshipLinkage<T,M>

java.lang.Object
java.lang.Record
com.kazforge.jsonapi.mapping.RelationshipLinkage<T,M>
Type Parameters:
T - the ordinary relationship target type
M - the application-owned identifier-meta type

public record RelationshipLinkage<T,M>(T target, @Nullable M meta) extends Record
Opt-in application-owned wrapper for one relationship linkage occurrence that carries identifier meta.

target() is mapped exactly as the corresponding ordinary relationship target would be. meta() maps exclusively to that occurrence's JSON:API ResourceIdentifier.meta; it is not relationship-level meta (Relationship.meta) and is not resource-level meta (ResourceObject.meta).

The wrapper is optional. Ordinary @JsonApiRelationship shapes — a single target, List/Set/array/Optional of targets, a direct ResourceIdentifier, or a custom linkage mapping — remain valid when identifier meta is not required. Applications that need per-linkage identifier meta declare the richer value:


 @JsonApiRelationship
 RelationshipLinkage<Person, AuthorMeta> author;

 @JsonApiRelationship
 List<RelationshipLinkage<Comment, CommentMeta>> comments;
 

meta == null supplies no identifier meta: the target is mapped normally, and any ResourceIdentifier.meta already present on a direct identifier target is left in place. When meta is present, the declared M converts through the configured authority and replaces the identifier's meta wholesale: conversion non-emission preserves any existing identifier meta, an emitted JSON null clears it, an emitted object replaces it, and any other emitted shape fails as an invalid meta target. The wrapper itself is not a JSON:API resource and is not independently patchable; identifier meta participates in presence-aware PATCH only as part of whole-linkage replacement.

  • Constructor Summary

    Constructors
    Constructor
    Description
    RelationshipLinkage(T target, @Nullable M meta)
    Creates an instance of a RelationshipLinkage record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    @Nullable M
    Returns the value of the meta record component.
    Returns the value of the target record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • RelationshipLinkage

      public RelationshipLinkage(T target, @Nullable M meta)
      Creates an instance of a RelationshipLinkage record class.
      Parameters:
      target - the value for the target record component
      meta - the value for the meta record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • target

      public T target()
      Returns the value of the target record component.
      Returns:
      the value of the target record component
    • meta

      public @Nullable M meta()
      Returns the value of the meta record component.
      Returns:
      the value of the meta record component