来自JSON数据源JasperReports的可选字段

时间:2017-01-03 16:29:41

标签: json jasper-reports

我正在使用JSON数据源在JasperReport中创建报表。内部iReport字段声明为Integer。该字段用于其他字段中的行。

输入JSON示例:

[{
    "dateFrom": "01.12.2016",
    "dateTo": "01.12.2016",
    "someOptionalNumber": 12
},
{
    "dateFrom": "01.12.2016",
    "dateTo": "01.12.2016"
}, {
    "dateFrom": "01.12.2016",
    "dateTo": "01.12.2016",
    "someOptionalNumber": 11
}]

现场声明:

<field name="someOptionalNumber" class="java.lang.Integer"/> 

问题是在输入JSON中someOptionalNumber是可选的,因此在每一行中都不存在。可以选择字段吗?

当我运行这样的JSON时,我得到了这个错误:

引起:net.sf.jasperreports.engine.JRException:无法获取类'java.lang.Integer'的字段'someOptionalNumber'的值

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[JRException: Unable to get value for field 'someOptionalNumber' of class 'java.lang.Integer']]
...
Caused by: net.sf.jasperreports.engine.JRException: Unable to get value for field 'someOptionalNumber' of class 'java.lang.Integer'
    at net.sf.jasperreports.engine.data.JsonDataSource.getFieldValue(JsonDataSource.java:241)
    at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1358)
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1259)
    at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1235)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1588)
    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:149)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:939)
    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:871)
    at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:114)
    at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
    at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:969)
    at reporting.engine.ReportEngine$.reporting$engine$ReportEngine$$createPDF(ReportEngine.scala:64)
...
Caused by: org.apache.commons.beanutils.ConversionException: Unparseable number: ""
    at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:241)
    at org.apache.commons.beanutils.locale.LocaleConvertUtilsBean.convert(LocaleConvertUtilsBean.java:285)
    at net.sf.jasperreports.engine.data.JRAbstractTextDataSource.convertStringValue(JRAbstractTextDataSource.java:70)
    at net.sf.jasperreports.engine.data.JsonDataSource.getFieldValue(JsonDataSource.java:231)
    ... 49 common frames omitted
Caused by: java.text.ParseException: Unparseable number: ""
    at java.text.NumberFormat.parse(NumberFormat.java:385)
    at org.apache.commons.beanutils.locale.converters.DecimalLocaleConverter.parse(DecimalLocaleConverter.java:253)
    at org.apache.commons.beanutils.locale.converters.IntegerLocaleConverter.parse(IntegerLocaleConverter.java:218)
    at org.apache.commons.beanutils.locale.BaseLocaleConverter.convert(BaseLocaleConverter.java:232)

1 个答案:

答案 0 :(得分:0)

我使用的是5.5.1版本的JasperReports,升级到最新版本(6.3.1)解决了问题dada67 sugested