Jump to content
Changes to the Jaspersoft community edition download ×

Jasperreport library, JsonDataSource empty fields


svoenix

Recommended Posts

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)?

Link to comment
Share on other sites

  • 5 weeks later...
  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

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.

 

Link to comment
Share on other sites

  • 3 months later...

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)[/code]

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

This one works perfect.

 

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...