net.sf.jasperreports.engine.data

## Class JsonDataSource

- java.lang.Object
- - net.sf.jasperreports.engine.data.JRAbstractTextDataSource
  - - net.sf.jasperreports.engine.data.JsonDataSource

- All Implemented Interfaces:
    JRDataSource, JRRewindableDataSource

      public class JsonDataSource
      extends JRAbstractTextDataSource
      implements JRRewindableDataSource

  JSON data source implementation
  Version:
    $Id: JsonDataSource.java 6923 2014-02-24 14:18:52Z teodord $
  Author:
    Narcis Marcu (narcism@users.sourceforge.net)

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `JsonDataSource(java.io.File file)`
    `JsonDataSource(java.io.File file, java.lang.String selectExpression)`
    `JsonDataSource(java.io.InputStream stream)`
    `JsonDataSource(java.io.InputStream jsonStream, java.lang.String selectExpression)`
    `JsonDataSource(JasperReportsContext jasperReportsContext, java.lang.String location, java.lang.String selectExpression)` Creates a data source instance that reads JSON data from a given location
    `JsonDataSource(java.lang.String location, java.lang.String selectExpression)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `close()`
    `java.lang.Object` | `getFieldValue(JRField jrField)` Gets the field value for the current position.
    `protected com.fasterxml.jackson.databind.JsonNode` | `getJsonData(com.fasterxml.jackson.databind.JsonNode rootNode, java.lang.String jsonExpression)` Extracts the JSON nodes based on the query expression
    `protected com.fasterxml.jackson.databind.JsonNode` | `goDownPath(com.fasterxml.jackson.databind.JsonNode rootNode, java.lang.String simplePath)` Extracts the JSON nodes under the simple path
    `protected com.fasterxml.jackson.databind.JsonNode` | `goDownPathWithAttribute(com.fasterxml.jackson.databind.JsonNode rootNode, java.lang.String pathWithAttributeExpression)` Extracts the JSON nodes that match the attribute expression
    `protected boolean` | `isValidExpression(com.fasterxml.jackson.databind.JsonNode operand, java.lang.String attributeExpression)` Validates an attribute expression on a JsonNode
    `void` | `moveFirst()` Moves back to the first element in the data source.
    `boolean` | `next()` Tries to position the cursor on the next element in the data source.
    `JsonDataSource` | `subDataSource()` Creates a sub data source using the current node as the base for its input stream.
    `JsonDataSource` | `subDataSource(java.lang.String selectExpression)` Creates a sub data source using the current node as the base for its input stream.

    - ### Methods inherited from class net.sf.jasperreports.engine.data.JRAbstractTextDataSource

      `convertNumber, convertStringValue, getConvertBean, getDatePattern, getFormattedDate, getFormattedNumber, getLocale, getNumberPattern, getTimeZone, setDatePattern, setLocale, setLocale, setNumberPattern, setTextAttributes, setTimeZone, setTimeZone`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### JsonDataSource

          public JsonDataSource(java.io.InputStream stream)
                         throws JRException

      Throws:
        `JRException`

    - #### JsonDataSource

          public JsonDataSource(java.io.InputStream jsonStream,
                        java.lang.String selectExpression)
                         throws JRException

      Throws:
        `JRException`

    - #### JsonDataSource

          public JsonDataSource(java.io.File file)
                         throws java.io.FileNotFoundException,
                                JRException

      Throws:
        `java.io.FileNotFoundException`
        `JRException`

    - #### JsonDataSource

          public JsonDataSource(java.io.File file,
                        java.lang.String selectExpression)
                         throws java.io.FileNotFoundException,
                                JRException

      Throws:
        `java.io.FileNotFoundException`
        `JRException`

    - #### JsonDataSource

          public JsonDataSource(JasperReportsContext jasperReportsContext,
                        java.lang.String location,
                        java.lang.String selectExpression)
                         throws JRException

      Creates a data source instance that reads JSON data from a given location
      Parameters:
        `jasperReportsContext` - the JasperReportsContext
        `location` - a String representing JSON data source
        `selectExpression` - a String representing the select expression
      Throws:
        `JRException`

    - #### JsonDataSource

          public JsonDataSource(java.lang.String location,
                        java.lang.String selectExpression)
                         throws JRException

      Throws:
        `JRException`
      See Also:
        `JsonDataSource(JasperReportsContext, String, String)`

  - ### Method Detail

    - #### moveFirst

          public void moveFirst()
                         throws JRException

      Description copied from interface: `JRRewindableDataSource`
      Moves back to the first element in the data source.
      Specified by:
        `moveFirst` in interface `JRRewindableDataSource`
      Throws:
        `JRException`

    - #### next

          public boolean next()

      Description copied from interface: `JRDataSource`
      Tries to position the cursor on the next element in the data source.
      Specified by:
        `next` in interface `JRDataSource`
      Returns:
        true if there is a next record, false otherwise

    - #### getFieldValue

          public java.lang.Object getFieldValue(JRField jrField)
                                         throws JRException

      Description copied from interface: `JRDataSource`
      Gets the field value for the current position.
      Specified by:
        `getFieldValue` in interface `JRDataSource`
      Returns:
        an object containing the field value. The object type must be the field object type.
      Throws:
        `JRException`

    - #### getJsonData

          protected com.fasterxml.jackson.databind.JsonNode getJsonData(com.fasterxml.jackson.databind.JsonNode rootNode,
                                                            java.lang.String jsonExpression)
                                                                 throws JRException

      Extracts the JSON nodes based on the query expression
      Parameters:
        `rootNode` -
        `jsonExpression` -
      Throws:
        `JRException`

    - #### goDownPathWithAttribute

          protected com.fasterxml.jackson.databind.JsonNode goDownPathWithAttribute(com.fasterxml.jackson.databind.JsonNode rootNode,
                                                                        java.lang.String pathWithAttributeExpression)
                                                                             throws JRException

      Extracts the JSON nodes that match the attribute expression
      Parameters:
        `rootNode` -
        `pathWithAttributeExpression` - : e.g. Orders(CustomerId == HILAA)
      Throws:
        `JRException`

    - #### goDownPath

          protected com.fasterxml.jackson.databind.JsonNode goDownPath(com.fasterxml.jackson.databind.JsonNode rootNode,
                                                           java.lang.String simplePath)

      Extracts the JSON nodes under the simple path
      Parameters:
        `rootNode` -
        `simplePath` - - a simple field name, with no selection by attribute

    - #### isValidExpression

          protected boolean isValidExpression(com.fasterxml.jackson.databind.JsonNode operand,
                                  java.lang.String attributeExpression)
                                       throws JRException

      Validates an attribute expression on a JsonNode
      Parameters:
        `operand` -
        `attributeExpression` -
      Throws:
        `JRException`

    - #### subDataSource

          public JsonDataSource subDataSource()
                                       throws JRException

      Creates a sub data source using the current node as the base for its input stream.
      Returns:
        the JSON sub data source
      Throws:
        `JRException`

    - #### subDataSource

          public JsonDataSource subDataSource(java.lang.String selectExpression)
                                       throws JRException

      Creates a sub data source using the current node as the base for its input stream. An additional expression specifies the select criteria that will be applied to the JSON tree node.
      Parameters:
        `selectExpression` -
      Returns:
        the JSON sub data source
      Throws:
        `JRException`

    - #### close

          public void close()

© 2001-2010 Jaspersoft Corporation www.jaspersoft.com