Reputation: 3071
I have a json datasource with arrays within arrays, I am using using subreports which have a datasource derived from using datasourceExpression and the 'subdata()' method on the master datasource.
My problem now is passing another list to another subreport, I don't want to use subdata again, what I need to do somehow is pass a field which contains the json text as a String from the current subreport into the next subreport as a json datasource.
Does anyone know how this can be achieved?
I am using iReport 5.6.0 to create the JasperReports's reports.
Upvotes: 1
Views: 2613
Reputation: 96
With a json like this:
{"records": { "Calificaciones":[ {"curso":1,"cursoCompleto":true,"asignaturas":[ {"asignatura":"Geometescriptiva 1"}, {"asignatura":"Geometescriptiva 2"}, {"asignatura":"Geometescriptiva 3"} ] } ] } }
I add to my main report the query "records.Calificaciones" to iterate on the first array and add the fields (curso, cursoCompleto, asignaturas) in the detail band of the main report (in this example the "curso" field will print the integer "1"), now to iterate on the nested array I set the field "asignaturas" as of type "java.lang.Object".
Then I add a subreport on the detail band, selecting in the "subreport properties": "Use a datasource expression" and the value for the datasource expression:
new net.sf.jasperreports.engine.data.JsonDataSource(new ByteArrayInputStream($F{asignaturas}.toString().getBytes()),"")
Then in the subreport I add the fields to the detail band (in this example the field "asignatura") and it would print the nested array accordingly, for every node of the main array.
Upvotes: 1