Class DocumentIdUtil
java.lang.Object
io.micronaut.serde.support.util.DocumentIdUtil
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 Summary
Modifier and TypeMethodDescriptionstatic io.micronaut.core.type.Argument<Object> collectionElementType(io.micronaut.core.type.Argument<?> type, String description) Resolves the element type of an array orIterablereference collection.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.static booleanhasObjectIdentity(@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.static booleanisDocumentId(io.micronaut.core.annotation.AnnotationMetadata annotationMetadata) Checks whether a property is the document-scoped identifier of its bean.static booleanisWritten(Serializer.EncoderContext context, DocumentIdSerializationReference<?> reference) Checks whether a bean has already been written in full in the current document.static voidmarkWritten(Serializer.EncoderContext context, DocumentIdSerializationReference<?> reference) Records that a bean has been written in full in the current document.static <B> voidregister(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.static @Nullable Objectresolve(Deserializer.DecoderContext context, Object id, io.micronaut.core.type.Argument<?> type) Resolves a bean registered in the current document.static voidresolveOrDefer(Deserializer.DecoderContext context, Object id, io.micronaut.core.type.Argument<?> type, PendingDocumentIdReference.DocumentIdConsumer consumer) Resolves a bean registered in the current document, or defers the reference until it is registered.
-
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
nullif 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 contextid- The identifierintrospection- The bean introspectionidArgument- The identifier propertybean- 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 contextid- The identifiertype- The expected bean type- Returns:
- The bean, or
nullif 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 contextid- The identifiertype- The expected bean typeconsumer- 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 contextreference- The bean's identifier reference- Returns:
trueif 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 contextreference- 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 orIterablereference collection.- Parameters:
type- The array orIterabletypedescription- A description of the failing operation, used in the error message- Returns:
- The element type
- Throws:
SerdeException- If the element type is not available
-