Class JsonRecordWriter


public class JsonRecordWriter extends TextStreamWriter
Writes JSON using the structure of each record's natural representation.
  • Constructor Details

    • JsonRecordWriter

      public JsonRecordWriter(File file)
    • JsonRecordWriter

      public JsonRecordWriter(Writer writer)
  • Method Details

    • isPretty

      public boolean isPretty()
      Indicates if line breaks and indentations should be added to output (default false).
    • setPretty

      public JsonRecordWriter setPretty(boolean pretty)
      Indicates if line breaks and indentations should be added to output (default false).
      Example output (pretty = true):
      [
        {
          "country":"Philippines"
          ,"capital":"Manila"
        }
      ]

      Example output (pretty = false):
      [{"country":"Philippines","capital":"Manila"}]

    • getRootFieldName

      public String getRootFieldName()
      Returns the name of the top-level field holding the records array, or null/empty to write a bare array (default is data).
    • setRootFieldName

      public JsonRecordWriter setRootFieldName(String rootFieldName)
      Sets the name of the top-level field holding the records array, or null/empty to write a bare array (default is data).
    • open

      public void open()
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class DataEndpoint
    • close

      public void close()
      Description copied from class: DataEndpoint
      Indicates that this endpoint has finished reading or writing.
      Overrides:
      close in class TextStreamWriter
    • writeImpl

      protected void writeImpl(Record record) throws Throwable
      Description copied from class: DataWriter
      Overridden by subclasses to write the specified record to this DataWriter.

      Contract for subclasses (see also docs/authoring/DataWriter.md):

      Specified by:
      writeImpl in class DataWriter
      Throws:
      Throwable
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class TextStreamWriter