Class JsonOutputFormatter
java.lang.Object
de.iip_ecosphere.platform.connectors.formatter.JsonOutputFormatter
- All Implemented Interfaces:
OutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonGenerator>>
@MachineFormatter
public class JsonOutputFormatter
extends Object
implements OutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonGenerator>>
JSON output formatter (preliminary).
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprivate static enumNested classes/interfaces inherited from interface de.iip_ecosphere.platform.connectors.formatter.OutputFormatter
OutputFormatter.OutputConverter<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate de.iip_ecosphere.platform.support.json.JsonGeneratorprivate Stringprivate Stack<JsonOutputFormatter.StructureType> private StringWriterFields inherited from interface de.iip_ecosphere.platform.connectors.formatter.OutputFormatter
SEPARATOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(String name, de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonGenerator> func) Adds information to one chunk of output.byte[]Completes a chunk of output data.private voidcleanNesting(String parent) Cleans up the nesting.voidEnds a structure started before.Returns the output converter.private voidInitializes the JSON writing.voidstartArrayStructure(String name) Starts an array structure.voidstartObjectStructure(String name) Starts an object structure.
-
Field Details
-
writer
-
gen
private de.iip_ecosphere.platform.support.json.JsonGenerator gen -
parentName
-
structures
-
-
Constructor Details
-
JsonOutputFormatter
public JsonOutputFormatter()
-
-
Method Details
-
cleanNesting
Cleans up the nesting.- Parameters:
parent- the target parent path- Throws:
IOException- when writing data fails
-
initialize
Initializes the JSON writing.- Throws:
IOException- if initialization fails
-
add
public void add(String name, de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonGenerator> func) throws IOException Description 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<de.iip_ecosphere.platform.support.json.JsonGenerator>>- Parameters:
name- optional data name field (may be null for none)func- the data to be added- Throws:
IOException- if adding the data fails for some reason
-
startArrayStructure
Description 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<de.iip_ecosphere.platform.support.json.JsonGenerator>>- Parameters:
name- optional data name field holding the array (may be null for none)- Throws:
IOException- if starting this structure fails
-
startObjectStructure
Description 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<de.iip_ecosphere.platform.support.json.JsonGenerator>>- Parameters:
name- optional data name field holding the array (may be null for none)- Throws:
IOException- if starting this structure fails
-
endStructure
Description copied from interface:OutputFormatterEnds a structure started before.- Specified by:
endStructurein interfaceOutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonGenerator>>- Throws:
IOException- if ending the actual structure fails
-
chunkCompleted
Description copied from interface:OutputFormatterCompletes a chunk of output data.- Specified by:
chunkCompletedin interfaceOutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonGenerator>>- Returns:
- the chunk
- Throws:
IOException- if creating the chunk fails for some reason
-
getConverter
Description copied from interface:OutputFormatterReturns the output converter.- Specified by:
getConverterin interfaceOutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonGenerator>>- Returns:
- the output converter
-