0

I am using a Json data source for my report. The json record contains some fields as well as a list of articles I need to iterate. So the json record would look something like the following:

{"client":"John Doe","invoiceNumber":"INV001",
"articles":[{"name":"Article1","price":40.00},{"name":"Article2","price":50.00}]}

I added a data set in my report for these articles and then added a list element for this data set to iterate the set. But the articles never get iterated on report generation. I have run the report through the jasper library to discover I am getting a warning in JsonQueryExecuter.createDatasource "No JSON source was provided". But when I created my list I specified "Use same connection to fill list". Can someone please tell me what the issue is here?

For reference here is a test report that does not iterate the articles:

<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="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="81afe112-ee1b-4443-8d1c-cb6d9ab95dd8">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Json Test"/>
    <subDataset name="Articles" uuid="fa853735-039f-482e-b16b-fad34f35c354">
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Json Test"/>
        <queryString language="json">
            <![CDATA[articles]]>
        </queryString>
        <field name="name" class="java.lang.String">
            <fieldDescription><![CDATA[name]]></fieldDescription>
        </field>
        <field name="price" class="java.lang.String">
            <fieldDescription><![CDATA[price]]></fieldDescription>
        </field>
        <group name="name">
            <groupExpression><![CDATA[$F{name}]]></groupExpression>
        </group>
        <group name="price">
            <groupExpression><![CDATA[$F{price}]]></groupExpression>
        </group>
    </subDataset>
    <queryString language="json">
        <![CDATA[articles]]>
    </queryString>
    <field name="name" class="java.lang.String">
        <fieldDescription><![CDATA[name]]></fieldDescription>
    </field>
    <field name="price" class="java.lang.String">
        <fieldDescription><![CDATA[price]]></fieldDescription>
    </field>
    <title>
        <band height="79" splitType="Stretch">
            <componentElement>
                <reportElement x="0" y="10" width="253" height="36" uuid="c3237c70-6b2e-43e3-aa21-5092d8b91afc"/>
                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="Articles" uuid="822fffb6-6a34-442e-a9dd-01fcbc25fbdc">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:listContents height="36" width="253">
                        <textField>
                            <reportElement x="10" y="0" width="100" height="30" uuid="07e3ff2a-3832-4b06-9275-cb1ee8e51cfe">
                                <property name="local_mesure_unitwidth" value="pixel"/>
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <property name="local_mesure_unitheight" value="pixel"/>
                                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                            </reportElement>
                            <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
                        </textField>
                        <textField>
                            <reportElement x="120" y="3" width="100" height="30" uuid="d58f36cb-41eb-4399-a0d9-a181f02c4931">
                                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                            </reportElement>
                            <textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
        </band>
    </title>
</jasperReport>
Alex K
  • 22,315
  • 19
  • 108
  • 236
user79074
  • 4,937
  • 5
  • 29
  • 57
  • 1
    First pass the jon datasource correctly see this http://stackoverflow.com/questions/33300592/jasper-reports-json-datasource-get-null-values, then checkout this for how to create the correct query http://stackoverflow.com/questions/34603844/how-to-create-multiple-tables-in-jasper-report-using-json-as-a-datasource – Petter Friberg Apr 15 '16 at 21:46
  • As code is currently I can't know if you are passing the json correctly, I see you querying 2 times the json datasource (both in main and in subdatset), I guess one should be removed, you are passing the connection? to the jr:list, hence you have multiple problems. – Petter Friberg Apr 15 '16 at 21:51
  • If you can't fix it all, post expected result and I will post an answer, for now I will duplicate this towards your first error ""No JSON source was provided" – Petter Friberg Apr 15 '16 at 21:52
  • also this may help http://stackoverflow.com/questions/33778753/dynamic-no-of-tables-in-jasper-report – Petter Friberg Apr 15 '16 at 21:58
  • Do I add this to my subDataset node? And if so how? – user79074 Apr 16 '16 at 11:44

0 Answers0