Class JsonDataSource

    • Field Detail

      • EXCEPTION_MESSAGE_KEY_JSON_FIELD_VALUE_NOT_RETRIEVED

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_JSON_FIELD_VALUE_NOT_RETRIEVED
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_INVALID_ATTRIBUTE_SELECTION

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_INVALID_ATTRIBUTE_SELECTION
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_INVALID_EXPRESSION

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_INVALID_EXPRESSION
        See Also:
        Constant Field Values
      • EXCEPTION_MESSAGE_KEY_NO_DATA

        public static final java.lang.String EXCEPTION_MESSAGE_KEY_NO_DATA
        See Also:
        Constant Field Values
      • PROPERTY_FIELD_EXPRESSION

        public static final java.lang.String PROPERTY_FIELD_EXPRESSION
        Property specifying the JSON expression for the dataset field.
        See Also:
        Constant Field Values
    • 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

        protected JsonDataSource​(com.fasterxml.jackson.databind.JsonNode jsonTree,
                                 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
    • Method Detail

      • getRootNode

        public com.fasterxml.jackson.databind.JsonNode getRootNode()
        Access the JDON tree that this data source is based on.
        Returns:
        the JSON tree used by this data source
      • 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​(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.
        Specified by:
        subDataSource in interface HierarchicalDataSource<JsonDataSource>
        Parameters:
        selectExpression -
        Returns:
        the JSON sub data source
        Throws:
        JRException
      • getFieldExpression

        protected java.lang.String getFieldExpression​(JRField field)