yuda yuda -4 years ago 286
Java Question

java ireport passing json as expression

i am following this tutorial to passing json to jrxml.
my dummy json file success parse into good looking report.

but i have trouble while passing json code to jrxml.
in this tutorial there is configuration like picture below

datasource

i tried to passing json like this

Map<String,Object> params = new HashMap<String,Object>();

String sPath = "/reports/master_standar_test_kertas.jrxml";
URL uReport = this.getClass().getResource(sPath);

String sJson = "{\"parameter\": { \"status\":\"success\" },\"data\":[{\"kode\":\"001\",\"title\":\"ENAMEL\"}]}";
System.out.println((new JSONObject(sJson)));
InputStream is = new ByteArrayInputStream(sJson.getBytes());
JsonDataSource source = new JsonDataSource(is);

params.put(JsonQueryExecuterFactory.JSON_SOURCE, is);

JasperReport jr = JasperCompileManager.compileReport(uReport.getPath());
JasperPrint jpPrint = JasperFillManager.fillReport(jr, params,source);
JasperViewer jpView = new JasperViewer(jpPrint);


but i got error

net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression for source text: $P{net.sf.jasperreports.json.source}


my question :


  1. I am sure my code is wrong, but i don't know the exact wrong code

  2. I am realy want to understand how jasperreport works, but i am new in java, what there is any tutorial that i can read...?


Answer Source
  1. I would try to set the JsonQueryExecuterFactory.JSON_INPUT_STREAM parameter instead, as it seems to be exactly what you need. The JsonQueryExecuterFactory.JSON_SOURCE parameter can only be:

    • a resource on the classpath
    • a file from the filesystem, with an absolute or relative path
    • a url
  2. Most of the resources for getting yourself familiar with JasperReports can be found on the Jaspersoft Community website. You may find useful the:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download