Package org.mule.metadata.persistence
Class AbstractJsonMetadataTypeWriter
- java.lang.Object
-
- org.mule.metadata.persistence.AbstractJsonMetadataTypeWriter
-
- All Implemented Interfaces:
TypeWriter,MetadataTypeWriter
- Direct Known Subclasses:
JsonMetadataTypeWriter,ReducedJsonMetadataTypeWriter
public abstract class AbstractJsonMetadataTypeWriter extends Object implements TypeWriter, MetadataTypeWriter
Base class forMetadataTypeWriters implementations that serializeMetadataTypeobjects into a readable and processable JSON file, that can be deserialize again into aMetadataTypeusing aSerializedMetadataTypeLoader.This class is not Thread-safe.
- Since:
- 1.2.0, 1.1.7
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanprettyPrintprotected Stack<MetadataType>typeStackprotected com.google.gson.stream.JsonWriterwriter
-
Constructor Summary
Constructors Constructor Description AbstractJsonMetadataTypeWriter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description AbstractJsonMetadataTypeWritersetPrettyPrint(boolean prettyPrint)Changes the value of PrettyPrint property of theReducedJsonMetadataTypeWriter.StringtoString(MetadataType structure)Given aMetadataType, serializes it into JSON format, the result of the serialization will be the output of the operation as aStringprotected abstract voidwrite(MetadataType type)Given aMetadataType, serializes it into a JSON format.voidwrite(MetadataType metadataType, com.google.gson.stream.JsonWriter writer)Given aMetadataType, serializes it into a JSON format, the result of the serialization will be written by the {@param writer}.
-
-
-
Field Detail
-
writer
protected com.google.gson.stream.JsonWriter writer
-
typeStack
protected Stack<MetadataType> typeStack
-
prettyPrint
protected boolean prettyPrint
-
-
Method Detail
-
toString
public String toString(MetadataType structure)
Given aMetadataType, serializes it into JSON format, the result of the serialization will be the output of the operation as aString- Specified by:
toStringin interfaceTypeWriter- Parameters:
structure-MetadataTypeto doSerialize.- Throws:
MetadataSerializingException- in any error case
-
write
public void write(MetadataType metadataType, com.google.gson.stream.JsonWriter writer) throws IOException
Given aMetadataType, serializes it into a JSON format, the result of the serialization will be written by the {@param writer}.- Specified by:
writein interfaceMetadataTypeWriter- Parameters:
metadataType-MetadataTypeto doSerialize.writer-JsonWriterwhich will be used to write the serializedMetadataType- Throws:
IOException- if any error occurred when writing the JSON file.
-
write
protected abstract void write(MetadataType type) throws IOException
Given aMetadataType, serializes it into a JSON format.It is expected that a proper writer is already set to this object.
- Parameters:
type-MetadataTypeto doSerialize.- Throws:
IOException- if any error occurred when writing the JSON file.
-
setPrettyPrint
public AbstractJsonMetadataTypeWriter setPrettyPrint(boolean prettyPrint)
Changes the value of PrettyPrint property of theReducedJsonMetadataTypeWriter. If it is enabled, whentoString(MetadataType)is executed the outputStringwill be printed in a human readable format, otherwise, by default, the JSON will be printed in a compact and more performable format.- Parameters:
prettyPrint- boolean value indicating if the writer should pretty print the JSON- Returns:
- the configured
TypeWriterinstance
-
-