Jump to content
We've recently updated our Privacy Statement, available here ×

inanutshellus

Members
  • Posts

    12
  • Joined

  • Last visited

 Content Type 

Profiles

Forum

Events

Featured Visualizations

Knowledge Base

Documentation (PDF Downloads)

Blog

Documentation (Test Area)

Documentation

Dr. Jaspersoft Webinar Series

Downloads

Posts posted by inanutshellus

  1. Looking in the source, turns out they don't support lists, so you can't do subdatasets without a flat file (which is how the subdataset is done in the Jasper Reports example).

    However, one of my devs has dropped a patch here:

    http://community.jaspersoft.com/jasperreports-library/issues/2500-0

    If you have a JSON List, declare it as an InputStream and send it to your subdataset. All we need now is someone to review the patch.

  2.  

    Given a simple JSON datasource, like so: 

     

     

        {
          "Customers": [
            {
              "ContactName": "John Doe",
              "Orders": [
                { "OrderID": 100 },
                { "OrderID": 101 }
              ]
            }, {
              "ContactName": "Jane Smith",
              "Orders": [
                { "OrderID": 102 },
                { "OrderID": 103 },
                { "OrderID": 104 }
              ]
            }
          ]
        }
     

     

    I can't seem to declare the field "Orders" as a List. 

     

    It blows up like so: 

     

     

        Error filling print... Unable to get value for field 'Orders' of class 'java.util.List'
        net.sf.jasperreports.engine.JRException: Unable to get value for field 'Orders' of class 'java.util.List'
             at net.sf.jasperreports.engine.data.JsonDataSource.getFieldValue(JsonDataSource.java:233)
             at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1317)
        [...]
             at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Caused by: net.sf.jasperreports.engine.JRException: Field 'Orders' is of class 'java.util.List' and cannot be converted
             at net.sf.jasperreports.engine.data.JsonDataSource.getFieldValue(JsonDataSource.java:230)
             ... 13 more
     

     

     

    To reproduce it, load the following JRXML into iReport, and try to run it with the above datasource. Notice I'm not even using the Orders!

     

     

        <?xml version="1.0" encoding="UTF-8"?>
        <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="deepJsonTest" language="groovy" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5f9dde08-ee77-4cc0-bfe5-199306a133a9">
            <property name="ireport.zoom" value="1.0"/>
            <property name="ireport.x" value="0"/>
            <property name="ireport.y" value="0"/>
            <queryString language="json">
                <![CDATA[Customers]]>
            </queryString>
            <field name="ContactName" class="java.lang.String">
                <fieldDescription><![CDATA[ContactName]]></fieldDescription>
            </field>
            <field name="Orders" class="java.util.List">
                <fieldDescription><![CDATA[Orders]]></fieldDescription>
            </field>
            <detail>
                <band height="153" splitType="Stretch">
                    <textField>
                        <reportElement uuid="923b522c-825e-4ebf-a3be-42802544f48f" x="0" y="0" width="100" height="20"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[$F{ContactName}]]></textFieldExpression>
                    </textField>
                </band>
            </detail>
        </jasperReport>
     
  3. I'm looking for unit tests for the JSON Datasource and don't see any tests in the codebase... Do you guys rely on the Samples as your tests or...?



    Post Edited by inanutshellus at 09/20/2012 17:05
  4. 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`.

     

×
×
  • Create New...