Package 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:
HierarchicalDataSource<JsonDataSource>,JsonData<JsonDataSource>,RandomAccessDataSource,JRDataSource,JRRewindableDataSource
public class JsonDataSource extends JRAbstractTextDataSource implements JsonData<JsonDataSource>, RandomAccessDataSource
JSON data source implementation- Author:
- Narcis Marcu (narcism@users.sourceforge.net)
-
-
Field Summary
Fields Modifier and Type Field Description static StringEXCEPTION_MESSAGE_KEY_INVALID_ATTRIBUTE_SELECTIONstatic StringEXCEPTION_MESSAGE_KEY_INVALID_EXPRESSIONstatic StringEXCEPTION_MESSAGE_KEY_JSON_FIELD_VALUE_NOT_RETRIEVEDstatic StringEXCEPTION_MESSAGE_KEY_NO_DATAstatic StringPROPERTY_FIELD_EXPRESSIONProperty specifying the JSON expression for the dataset field.-
Fields inherited from class net.sf.jasperreports.engine.data.JRAbstractTextDataSource
EXCEPTION_MESSAGE_KEY_CANNOT_CONVERT_FIELD_TYPE, EXCEPTION_MESSAGE_KEY_CANNOT_MODIFY_PROPERTIES_AFTER_START, EXCEPTION_MESSAGE_KEY_NODE_NOT_AVAILABLE, EXCEPTION_MESSAGE_KEY_NULL_DOCUMENT, EXCEPTION_MESSAGE_KEY_NULL_SELECT_EXPRESSION, EXCEPTION_MESSAGE_KEY_UNKNOWN_COLUMN_NAME, EXCEPTION_MESSAGE_KEY_UNKNOWN_NUMBER_TYPE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedJsonDataSource(com.fasterxml.jackson.databind.JsonNode jsonTree, String selectExpression)JsonDataSource(File file)JsonDataSource(File file, String selectExpression)JsonDataSource(InputStream stream)JsonDataSource(InputStream jsonStream, String selectExpression)JsonDataSource(String location, String selectExpression)JsonDataSource(JasperReportsContext jasperReportsContext, String location, String selectExpression)Creates a data source instance that reads JSON data from a given locationJsonDataSource(RepositoryContext repositoryContext, String location, String selectExpression)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcurrentIndex()protected StringgetFieldExpression(JRField field)ObjectgetFieldValue(JRField jrField)Gets the field value for the current position.protected com.fasterxml.jackson.databind.JsonNodegetJsonData(com.fasterxml.jackson.databind.JsonNode rootNode, String jsonExpression)Extracts the JSON nodes based on the query expressioncom.fasterxml.jackson.databind.JsonNodegetRootNode()Access the JDON tree that this data source is based on.protected com.fasterxml.jackson.databind.JsonNodegoDownPath(com.fasterxml.jackson.databind.JsonNode rootNode, String simplePath)Extracts the JSON nodes under the simple pathprotected com.fasterxml.jackson.databind.JsonNodegoDownPathWithAttribute(com.fasterxml.jackson.databind.JsonNode rootNode, String pathWithAttributeExpression)Extracts the JSON nodes that match the attribute expressionprotected booleanisValidExpression(com.fasterxml.jackson.databind.JsonNode operand, String attributeExpression)Validates an attribute expression on a JsonNodevoidmoveFirst()Moves back to the first element in the data source.voidmoveToRecord(int index)booleannext()Tries to position the cursor on the next element in the data source.intrecordCount()JsonDataSourcesubDataSource()Creates a sub data source using the current node as the base for its input stream.JsonDataSourcesubDataSource(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, getLocale, getNumberPattern, getTextAttributes, getTimeZone, setDatePattern, setLocale, setLocale, setNumberPattern, setTextAttributes, setTextAttributes, setTimeZone, setTimeZone
-
-
-
-
Field Detail
-
EXCEPTION_MESSAGE_KEY_JSON_FIELD_VALUE_NOT_RETRIEVED
public static final String EXCEPTION_MESSAGE_KEY_JSON_FIELD_VALUE_NOT_RETRIEVED
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_INVALID_ATTRIBUTE_SELECTION
public static final String EXCEPTION_MESSAGE_KEY_INVALID_ATTRIBUTE_SELECTION
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_INVALID_EXPRESSION
public static final String EXCEPTION_MESSAGE_KEY_INVALID_EXPRESSION
- See Also:
- Constant Field Values
-
EXCEPTION_MESSAGE_KEY_NO_DATA
public static final String EXCEPTION_MESSAGE_KEY_NO_DATA
- See Also:
- Constant Field Values
-
PROPERTY_FIELD_EXPRESSION
public static final String PROPERTY_FIELD_EXPRESSION
Property specifying the JSON expression for the dataset field.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JsonDataSource
public JsonDataSource(InputStream stream) throws JRException
- Throws:
JRException
-
JsonDataSource
public JsonDataSource(InputStream jsonStream, String selectExpression) throws JRException
- Throws:
JRException
-
JsonDataSource
protected JsonDataSource(com.fasterxml.jackson.databind.JsonNode jsonTree, String selectExpression) throws JRException- Throws:
JRException
-
JsonDataSource
public JsonDataSource(File file) throws FileNotFoundException, JRException
- Throws:
FileNotFoundExceptionJRException
-
JsonDataSource
public JsonDataSource(File file, String selectExpression) throws FileNotFoundException, JRException
- Throws:
FileNotFoundExceptionJRException
-
JsonDataSource
public JsonDataSource(JasperReportsContext jasperReportsContext, String location, String selectExpression) throws JRException
Creates a data source instance that reads JSON data from a given location- Parameters:
jasperReportsContext- the JasperReportsContextlocation- a String representing JSON data sourceselectExpression- a String representing the select expression- Throws:
JRException
-
JsonDataSource
public JsonDataSource(RepositoryContext repositoryContext, String location, String selectExpression) throws JRException
- Throws:
JRException
-
JsonDataSource
public JsonDataSource(String location, String selectExpression) throws JRException
- Throws:
JRException- See Also:
JsonDataSource(JasperReportsContext, String, String)
-
-
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
-
moveFirst
public void moveFirst() throws JRExceptionDescription copied from interface:JRRewindableDataSourceMoves back to the first element in the data source.- Specified by:
moveFirstin interfaceJRRewindableDataSource- Throws:
JRException
-
next
public boolean next()
Description copied from interface:JRDataSourceTries to position the cursor on the next element in the data source.- Specified by:
nextin interfaceJRDataSource- Returns:
- true if there is a next record, false otherwise
-
recordCount
public int recordCount()
- Specified by:
recordCountin interfaceRandomAccessDataSource
-
currentIndex
public int currentIndex()
- Specified by:
currentIndexin interfaceRandomAccessDataSource
-
moveToRecord
public void moveToRecord(int index) throws NoRecordAtIndexException- Specified by:
moveToRecordin interfaceRandomAccessDataSource- Throws:
NoRecordAtIndexException
-
getFieldValue
public Object getFieldValue(JRField jrField) throws JRException
Description copied from interface:JRDataSourceGets the field value for the current position.- Specified by:
getFieldValuein interfaceJRDataSource- 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, String jsonExpression) throws JRExceptionExtracts 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, String pathWithAttributeExpression) throws JRExceptionExtracts 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, 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, String attributeExpression) throws JRExceptionValidates 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.- Specified by:
subDataSourcein interfaceHierarchicalDataSource<JsonDataSource>- Returns:
- the JSON sub data source
- Throws:
JRException
-
subDataSource
public JsonDataSource subDataSource(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:
subDataSourcein interfaceHierarchicalDataSource<JsonDataSource>- Parameters:
selectExpression-- Returns:
- the JSON sub data source
- Throws:
JRException
-
-