Class JsonOutputFormatter
- java.lang.Object
-
- de.iip_ecosphere.platform.connectors.formatter.JsonOutputFormatter
-
- All Implemented Interfaces:
OutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator>>
@MachineFormatter public class JsonOutputFormatter extends java.lang.Object implements OutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator>>
JSON output formatter (preliminary).- Author:
- Holger Eichelberger, SSE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJsonOutputFormatter.JsonOutputConverterprivate static classJsonOutputFormatter.StructureType-
Nested classes/interfaces inherited from interface de.iip_ecosphere.platform.connectors.formatter.OutputFormatter
OutputFormatter.OutputConverter<T>
-
-
Field Summary
Fields Modifier and Type Field Description private com.fasterxml.jackson.core.JsonGeneratorgenprivate com.fasterxml.jackson.databind.ObjectMapperobjectMapperprivate java.lang.StringparentNameprivate java.util.Stack<JsonOutputFormatter.StructureType>structuresprivate java.io.StringWriterwriter-
Fields inherited from interface de.iip_ecosphere.platform.connectors.formatter.OutputFormatter
SEPARATOR
-
-
Constructor Summary
Constructors Constructor Description JsonOutputFormatter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.String name, de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator> func)Adds information to one chunk of output.byte[]chunkCompleted()Completes a chunk of output data.private voidcleanNesting(java.lang.String parent)Cleans up the nesting.voidendStructure()Ends a structure started before.JsonOutputFormatter.JsonOutputConvertergetConverter()Returns the output converter.private voidinitialize()Initializes the JSON writing.voidstartArrayStructure(java.lang.String name)Starts an array structure.voidstartObjectStructure(java.lang.String name)Starts an object structure.
-
-
-
Field Detail
-
objectMapper
private com.fasterxml.jackson.databind.ObjectMapper objectMapper
-
writer
private java.io.StringWriter writer
-
gen
private com.fasterxml.jackson.core.JsonGenerator gen
-
parentName
private java.lang.String parentName
-
structures
private java.util.Stack<JsonOutputFormatter.StructureType> structures
-
-
Method Detail
-
cleanNesting
private void cleanNesting(java.lang.String parent) throws java.io.IOExceptionCleans up the nesting.- Parameters:
parent- the target parent path- Throws:
java.io.IOException- when writing data fails
-
initialize
private void initialize() throws java.io.IOExceptionInitializes the JSON writing.- Throws:
java.io.IOException- if initialization fails
-
add
public void add(java.lang.String name, de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator> func) throws java.io.IOExceptionDescription copied from interface:OutputFormatterAdds information to one chunk of output. Hierarchical names separated byOutputFormatter.SEPARATORcan be used, but nested values for the same parent (object) field must be named in sequence.- Specified by:
addin interfaceOutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator>>- Parameters:
name- optional data name field (may be null for none)func- the data to be added- Throws:
java.io.IOException- if adding the data fails for some reason
-
startArrayStructure
public void startArrayStructure(java.lang.String name) throws java.io.IOExceptionDescription copied from interface:OutputFormatterStarts an array structure. FollowingOutputFormatter.add(String, Object)calls will add elements to the array. Must be closed withOutputFormatter.endStructure()- Specified by:
startArrayStructurein interfaceOutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator>>- Parameters:
name- optional data name field holding the array (may be null for none)- Throws:
java.io.IOException- if starting this structure fails
-
startObjectStructure
public void startObjectStructure(java.lang.String name) throws java.io.IOExceptionDescription copied from interface:OutputFormatterStarts an object structure. FollowingOutputFormatter.add(String, Object)calls will add elements to the object. Must be closed withOutputFormatter.endStructure()- Specified by:
startObjectStructurein interfaceOutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator>>- Parameters:
name- optional data name field holding the array (may be null for none)- Throws:
java.io.IOException- if starting this structure fails
-
endStructure
public void endStructure() throws java.io.IOExceptionDescription copied from interface:OutputFormatterEnds a structure started before.- Specified by:
endStructurein interfaceOutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator>>- Throws:
java.io.IOException- if ending the actual structure fails
-
chunkCompleted
public byte[] chunkCompleted() throws java.io.IOExceptionDescription copied from interface:OutputFormatterCompletes a chunk of output data.- Specified by:
chunkCompletedin interfaceOutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator>>- Returns:
- the chunk
- Throws:
java.io.IOException- if creating the chunk fails for some reason
-
getConverter
public JsonOutputFormatter.JsonOutputConverter getConverter()
Description copied from interface:OutputFormatterReturns the output converter.- Specified by:
getConverterin interfaceOutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<com.fasterxml.jackson.core.JsonGenerator>>- Returns:
- the output converter
-
-