Class DocumentIdUtil

java.lang.Object
io.micronaut.serde.support.util.DocumentIdUtil

@Internal public final class DocumentIdUtil extends Object
Support for document-scoped identifiers: JAXB @XmlID and Jackson @JsonIdentityInfo properties share the SerdeConfig.SerManagedRef.Scope.DOCUMENT marker, one registry per document and the same reference serdes.
Since:
3.2
  • Method Details

    • isDocumentId

      public static boolean isDocumentId(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata)
      Checks whether a property is the document-scoped identifier of its bean.
      Parameters:
      annotationMetadata - The annotation metadata of a property
      Returns:
      Whether the property is the document-scoped identifier of its bean
    • findDocumentIdProperty

      public static <T> @Nullable io.micronaut.core.beans.BeanProperty<T,Object> findDocumentIdProperty(io.micronaut.core.beans.BeanIntrospection<T> introspection)
      Finds the document-scoped identifier property of a bean.
      Type Parameters:
      T - The bean type
      Parameters:
      introspection - The bean introspection
      Returns:
      The document-scoped identifier property, or null if the bean has none
    • hasObjectIdentity

      public static boolean hasObjectIdentity(@Nullable io.micronaut.core.beans.BeanProperty<?,?> documentIdProperty)
      Checks whether a document-scoped identifier carries object identity semantics, meaning repeated occurrences of the bean in a document are written and read as the identifier.
      Parameters:
      documentIdProperty - The document-scoped identifier property
      Returns:
      Whether the identifier carries object identity semantics
    • register

      public static <B> void register(Deserializer.DecoderContext context, Object id, io.micronaut.core.beans.BeanIntrospection<B> introspection, io.micronaut.core.type.Argument<Object> idArgument, B bean)
      Registers a fully read bean under its identifier for the current document.
      Type Parameters:
      B - The bean type
      Parameters:
      context - The decoder context
      id - The identifier
      introspection - The bean introspection
      idArgument - The identifier property
      bean - The bean
    • resolve

      public static @Nullable Object resolve(Deserializer.DecoderContext context, Object id, io.micronaut.core.type.Argument<?> type)
      Resolves a bean registered in the current document.
      Parameters:
      context - The decoder context
      id - The identifier
      type - The expected bean type
      Returns:
      The bean, or null if no compatible bean was registered under the identifier
    • resolveOrDefer

      public static void resolveOrDefer(Deserializer.DecoderContext context, Object id, io.micronaut.core.type.Argument<?> type, PendingDocumentIdReference.DocumentIdConsumer consumer) throws IOException
      Resolves a bean registered in the current document, or defers the reference until it is registered.
      Parameters:
      context - The decoder context
      id - The identifier
      type - The expected bean type
      consumer - Receives the bean
      Throws:
      IOException - If the reference cannot be set
    • isWritten

      public static boolean isWritten(Serializer.EncoderContext context, DocumentIdSerializationReference<?> reference)
      Checks whether a bean has already been written in full in the current document.
      Parameters:
      context - The encoder context
      reference - The bean's identifier reference
      Returns:
      true if the bean was written before and must now be written as its identifier
    • markWritten

      public static void markWritten(Serializer.EncoderContext context, DocumentIdSerializationReference<?> reference)
      Records that a bean has been written in full in the current document.
      Parameters:
      context - The encoder context
      reference - The bean's identifier reference
    • collectionElementType

      public static io.micronaut.core.type.Argument<Object> collectionElementType(io.micronaut.core.type.Argument<?> type, String description) throws SerdeException
      Resolves the element type of an array or Iterable reference collection.
      Parameters:
      type - The array or Iterable type
      description - A description of the failing operation, used in the error message
      Returns:
      The element type
      Throws:
      SerdeException - If the element type is not available