SubDatasets (lists inside lists) in json?

0
Jasper Reports comes with a sample report using a JSON datasource, and the "jsonCustomerReport" shows exactly what I want it to, but it does so by requerying the entire datasource for each subreport, like so:
 
 
<subreportParameter name="net.sf.jasperreports.json.source">
<subreportParameterExpression><![CDATA["data/northwind.json"]]></subreportParameterExpression>
</subreportParameter>
 
Let's say I wanted the Customer Report that looks like this:
 
    Maria Anders of Beverly Hills
        Order #100 
        Order #101
    Ana Trujillo of New York City
        Order #102
        Order #103
        Order #104
 
 
But using this data as a string passed in as an InputStream:
 
    {"SomeJsonObject": {
      "Customers": [ {
          "ContactName": "Maria Anders",
          "CustomerID": "ALFKI",
          "Address": {
              "Street":"123 Sesame St",
              "City":"Beverly Hills"
          },
          "Orders": [ {
              "OrderID": 100 // Other stuff snipped
            }, {
              "OrderID": 101
            }
          ]
        }, {
          "ContactName": "Ana Trujillo",
          "CustomerID": "ANATR",
          "Address": {
              "Street":"456 Sesame St",
              "City":"New York City"
          },
          "Orders": [ {
              "OrderID": 102
            }, {
              "OrderID": 103
            }, {
              "OrderID": 104
            }
          ]}
        ]}
    }
 
 
How would I access the Orders array?
 
I wanted to use a SubDataSet and a List component, but I don't know what to put for the `dataSourceExpression`.
 
inanutshellus's picture
Joined: Aug 25 2010 - 12:16pm
Last seen: 1 year 6 months ago

2 Answers:

0

The answer is, in fact, that JSON datasources do not support lists without this patch:

http://community.jaspersoft.com/comment/reply/705457

 

inanutshellus's picture
Joined: Aug 25 2010 - 12:16pm
Last seen: 1 year 6 months ago

Of course you could tie a JSON data source to a list and pull data out of it. But for this case, though, more work needs to be done.

Please visit this issue: http://community.jaspersoft.com/jasperreports-library/issues/2500-0
Basically it's the same request that you pointed to, only that it has been turned into an issue now.

narcism - 1 year 8 months ago

I notice the ticket has been stuck on "Feedback Requested" for a while. From whom are you expecting feedback? Other Jasper SE staff? The Author? Arbitrary netizens such as myself?

inanutshellus - 1 year 6 months ago
1

This article was written with MongoDB in mind. But it should apply equally well to your JSON data source. Does that solve it for you?

mdahlman's picture
1555
Joined: Mar 13 2007 - 2:43am
Last seen: 11 months 2 weeks ago
Pretty spot-on blog post. JRMapCollectionDataSource seems to be exactly what I want, though I can't seem to even *declare* a Field of type java.util.List in a JSON report. Any idea what that's about?
inanutshellus - 1 year 10 months ago
Feedback
randomness