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
  • Field Details

  • Constructor Details

    • JsonOutputFormatter

      public JsonOutputFormatter()
  • Method Details

    • cleanNesting

      private void cleanNesting(String parent) throws IOException
      Cleans up the nesting.
      Parameters:
      parent - the target parent path
      Throws:
      IOException - when writing data fails
    • initialize

      private void initialize() throws IOException
      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: OutputFormatter
      Adds information to one chunk of output. Hierarchical names separated by OutputFormatter.SEPARATOR can be used, but nested values for the same parent (object) field must be named in sequence.
      Specified by:
      add in interface OutputFormatter<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

      public void startArrayStructure(String name) throws IOException
      Description copied from interface: OutputFormatter
      Starts an array structure. Following OutputFormatter.add(String, Object) calls will add elements to the array. Must be closed with OutputFormatter.endStructure()
      Specified by:
      startArrayStructure in interface OutputFormatter<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

      public void startObjectStructure(String name) throws IOException
      Description copied from interface: OutputFormatter
      Starts an object structure. Following OutputFormatter.add(String, Object) calls will add elements to the object. Must be closed with OutputFormatter.endStructure()
      Specified by:
      startObjectStructure in interface OutputFormatter<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

      public void endStructure() throws IOException
      Description copied from interface: OutputFormatter
      Ends a structure started before.
      Specified by:
      endStructure in interface OutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonGenerator>>
      Throws:
      IOException - if ending the actual structure fails
    • chunkCompleted

      public byte[] chunkCompleted() throws IOException
      Description copied from interface: OutputFormatter
      Completes a chunk of output data.
      Specified by:
      chunkCompleted in interface OutputFormatter<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: OutputFormatter
      Returns the output converter.
      Specified by:
      getConverter in interface OutputFormatter<de.iip_ecosphere.platform.support.function.IOConsumer<de.iip_ecosphere.platform.support.json.JsonGenerator>>
      Returns:
      the output converter