Jasperreport library, JsonDataSource empty fields

I'm using below code to generate pdf using JsonDataSource and Jasperreport library.
InputStream input = new FileInputStream(new File("JsonExample.jrxml"));
InputStream is = new FileInputStream("search.json");
JsonDataSource app = new JsonDataSource(is);
JasperDesign jasperDesign = JRXmlLoader.load(input);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, new HashMap<String, Object>(), app);
OutputStream out = new FileOutputStream(new File("raport.pdf"));
JasperExportManager.exportReportToPdfStream(jasperPrint, out);
When I'm generating this report in Jasper Studio data fileds are correctly displayed (are not empty), but when I'm using above code, generated report contains onlny static text fields, there are no data fields with values read from json file. How to use Jasperreport library and JsonDataSource (5.5. version)?
svoenix's picture
Joined: Jan 8 2014 - 4:50am
Last seen: 9 years 8 months ago

I have the same problem too. Is there any solutions for this?

In my case, I fill the report using the following:

File file = new File("src/main/resources/data/simple.json");
JsonDataSource ds = new JsonDataSource(file);
JasperFillManager.fillReportToFile("src/main/resources/reports/json-simple.jasper", null, ds);

I am using 5.5 version as well. I tried to fill the report using json with ireport and it does not show the fields.

 

wid.kencono - 9 years 7 months ago

I am not sure about file input - what I've done is String input which is a json -

def jsonBytes = ((String) jsonData ).getBytes()
streamForReportSource = new ByteArrayInputStream(jsonBytes);
dataSource = new JsonDataSource(streamForReportSource, _defaultJSONSelectExpression)
reportDef.jasperPrinter = JasperFillManager.fillReport(reportDef.getReport().inputStream, reportDef.parameters, dataSource)

reportDef is nothing but JasperReportDef in grails- jasper plugin. One doesn't have to use this though.

This one works perfect.

dsrini.open - 9 years 4 months ago

Could you post your JsonExample.jrxml?

narcism - 9 years 3 months ago
show 3 more...

What is "_defaultJSONSelectExpression"?  I was having the same problem and switched to using the InputStream and am still getting no data in my report.

 

dwalton_2 - 8 years 2 months ago
narcism - 8 years 2 months ago

Thanks!  That really cleared things up for me.

dwalton_2 - 8 years 2 months ago

0 Answers:

No answers yet
Feedback
randomness