Package org.mule.metadata.persistence
Class DefaultObjectTypeReferenceHandler
- java.lang.Object
-
- org.mule.metadata.persistence.DefaultObjectTypeReferenceHandler
-
- All Implemented Interfaces:
ObjectTypeReferenceHandler
public class DefaultObjectTypeReferenceHandler extends Object implements ObjectTypeReferenceHandler
Implementation ofObjectTypeReferenceHandlerwhich handles references by looking for theMetadataTypeConstants.REF_FLAGprefix.- Since:
- 1.0
-
-
Constructor Summary
Constructors Constructor Description DefaultObjectTypeReferenceHandler(SerializationContext serializationContext)Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<TypeBuilder>readReference(String typeReference)IftypeReferencehas theMetadataTypeConstants.REF_FLAGthen it returns the type registered on theserializationContextunder such key.booleanshouldWriteReference(ObjectType type)Given anObjectTyperetrieves if should be written as a reference or not.Optional<String>writeReference(ObjectType type, com.google.gson.stream.JsonWriter writer)Uses thewriterto write a reference to the giventype.
-
-
-
Constructor Detail
-
DefaultObjectTypeReferenceHandler
public DefaultObjectTypeReferenceHandler(SerializationContext serializationContext)
Creates a new instance- Parameters:
serializationContext- aSerializationContextto keep track of the references
-
-
Method Detail
-
readReference
public Optional<TypeBuilder> readReference(String typeReference)
IftypeReferencehas theMetadataTypeConstants.REF_FLAGthen it returns the type registered on theserializationContextunder such key.- Specified by:
readReferencein interfaceObjectTypeReferenceHandler- Parameters:
typeReference- a reference- Returns:
- an
OptionalTypeBuilder
-
shouldWriteReference
public boolean shouldWriteReference(ObjectType type)
Given anObjectTyperetrieves if should be written as a reference or not.Default implementation returns `true` to maintain backwards compatibility.
- Specified by:
shouldWriteReferencein interfaceObjectTypeReferenceHandler- Parameters:
type- the type to write- Returns:
- whether the type should be written or not.
-
writeReference
public Optional<String> writeReference(ObjectType type, com.google.gson.stream.JsonWriter writer)
Uses thewriterto write a reference to the giventype.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.
- Specified by:
writeReferencein interfaceObjectTypeReferenceHandler- Parameters:
type- the type to writewriter- aJsonWriter- Returns:
- the reference that was written or
Optional.empty()
-
-