public class DefaultObjectTypeReferenceHandler extends Object implements ObjectTypeReferenceHandler
ObjectTypeReferenceHandler which handles references by looking for the
MetadataTypeConstants.REF_FLAG prefix.| Constructor and Description |
|---|
DefaultObjectTypeReferenceHandler(SerializationContext serializationContext)
Creates a new instance
|
| Modifier and Type | Method and Description |
|---|---|
Optional<TypeBuilder> |
readReference(String typeReference)
If
typeReference has the MetadataTypeConstants.REF_FLAG then it returns the type registered on the
serializationContext under such key. |
boolean |
shouldWriteReference(ObjectType type)
Given an
ObjectType retrieves if should be written as a reference or not. |
Optional<String> |
writeReference(ObjectType type,
com.google.gson.stream.JsonWriter writer)
Uses the
writer to write a reference to the given type. |
public DefaultObjectTypeReferenceHandler(SerializationContext serializationContext)
serializationContext - a SerializationContext to keep track of the referencespublic Optional<TypeBuilder> readReference(String typeReference)
typeReference has the MetadataTypeConstants.REF_FLAG then it returns the type registered on the
serializationContext under such key.readReference in interface ObjectTypeReferenceHandlertypeReference - a referenceOptional TypeBuilderpublic boolean shouldWriteReference(ObjectType type)
ObjectType retrieves if should be written as a reference or not.
Default implementation returns `true` to maintain backwards compatibility.
shouldWriteReference in interface ObjectTypeReferenceHandlertype - the type to writepublic Optional<String> writeReference(ObjectType type, com.google.gson.stream.JsonWriter writer)
writer to write a reference to the given type.
This method returns the written reference, so that it can be used as an id to deserialize. However, some implementations
might be unable to handle some specific types, which is why the reference might be Optional.empty().
In such case, it's the invoker responsibility to either attempt using a different implementation of this contract or to just treat the type explicitly instead of through a reference.
writeReference in interface ObjectTypeReferenceHandlertype - the type to writewriter - a JsonWriterOptional.empty()Copyright © 2025 MuleSoft, Inc.. All rights reserved.