Class JsonRecordReader


public class JsonRecordReader extends DataReader
Obtains records from a JSON stream, turning each object, array or field matched by a record break into one record that keeps nested objects and arrays as nested records and arrays.
  • Constructor Details

    • JsonRecordReader

      public JsonRecordReader(com.fasterxml.jackson.core.JsonParser reader)
    • JsonRecordReader

      public JsonRecordReader(File file)
    • JsonRecordReader

      public JsonRecordReader(Reader reader)
  • Method Details

    • createFactory

      protected com.fasterxml.jackson.core.JsonFactory createFactory()
      Creates the Jackson factory that the File and Reader constructors parse with; the default allows comments, single quotes and unquoted field names.
    • isDebug

      public boolean isDebug()
      Indicates if each JSON token read is logged at debug level (default is false).
    • setDebug

      public JsonRecordReader setDebug(boolean debug)
      Indicates if each JSON token read is logged at debug level (default is false).
    • isUseBigDecimal

      public boolean isUseBigDecimal()
      Indicates if decimal numbers are read as BigDecimal instead of Double (default is false).
    • setUseBigDecimal

      public JsonRecordReader setUseBigDecimal(boolean useBigDecimal)
      Indicates if decimal numbers are read as BigDecimal instead of Double (default is false).
    • isUseBigInteger

      public boolean isUseBigInteger()
      Returns whether BigInteger should be used for reading large numeric values. When enabled, integer values are read as BigInteger instead of Long to handle values larger than Long.MAX_VALUE.
      Returns:
      true if BigInteger is used for numeric values, false otherwise (default is false)
    • setUseBigInteger

      public JsonRecordReader setUseBigInteger(boolean useBigInteger)
      Sets whether BigInteger should be used for reading large numeric values. When enabled, integer values are read as BigInteger instead of Long to handle values larger than Long.MAX_VALUE.
      Parameters:
      useBigInteger - true to use BigInteger, false to use Long (default is false)
      Returns:
      this JsonRecordReader instance for method chaining
    • addRecordBreak

      public JsonRecordReader addRecordBreak(String locationPathAsString)
      Adds a location path (for example //array/object) matching the JSON objects, arrays or fields to read as records.
    • isRecordBreak

      protected boolean isRecordBreak(JsonXmlNode node)
      Returns true if the node matches any location path added with addRecordBreak(String).
    • close

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

      protected Record readImpl() throws Throwable
      Description copied from class: DataReader
      Overridden by subclasses to read the next record from this DataReader. The default implementation of DataReader.read() now insures that this method will not be called again after it returns a null.

      If no record is available, null will be returned.

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

      Specified by:
      readImpl in class DataReader
      Throws:
      Throwable
    • nextNode

      protected boolean nextNode() throws DataException
      Advances to the next JSON token and updates the current node; returns false at the end of the input.
      Throws:
      DataException
    • newNode

      protected JsonXmlNode newNode(JsonXmlNode parentNode, com.fasterxml.jackson.core.JsonToken token, String name, com.fasterxml.jackson.core.JsonLocation tokenLocation)
      Creates the node for the start of a JSON object or array (named object or array).
    • newField

      protected JsonXmlNode newField(JsonXmlNode parentNode, com.fasterxml.jackson.core.JsonToken token, String name, com.fasterxml.jackson.core.JsonLocation tokenLocation)
      Creates the node for a JSON field name; a scalar value is later stored on it by newValue(JsonXmlNode, JsonToken, Object).
    • newValue

      protected JsonXmlNode newValue(JsonXmlNode parentNode, com.fasterxml.jackson.core.JsonToken token, Object value)
      Stores a scalar value on the current field node, or in a new child node when inside an array, and returns that node.
    • isLineageSupported

      public boolean isLineageSupported()
      Description copied from class: DataReader
      Indicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).
      Overrides:
      isLineageSupported in class DataReader
    • addLineage

      protected Record addLineage(Record record)
      Description copied from class: DataReader
      Called by DataReader.read() for each record from DataReader.readImpl() while lineage is saved; the default copies recordLineage into every field along with its original index and name. Overrides set their source details on recordLineage first and end with super.addLineage(record).
      Overrides:
      addLineage in class DataReader
    • 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 DataReader
    • isAutoCloseReader

      public boolean isAutoCloseReader()
    • setAutoCloseReader

      public JsonRecordReader setAutoCloseReader(boolean autoCloseReader)