My sample json file content
{
"FlightLog":{
"FlightLog.crewMembers":[
],
"destinationStationCode":"JPN",
"FlightLog.destinationStationCode":"IND",
"FlightLog.originStationCode":"IND",
"FlightLog._lockVersion":"0",
"FlightLog.flightNum":"123"
}
}
I want to get value for FlightLog.FlightLog.originStationCode.
for eg: When i declare field name as below , i am getting the value "JPN"
<field name="FlightLog.destinationStationCode" class="java.lang.String">
<fieldDescription><![CDATA[FlightLog.destinationStationCode]]></fieldDescription>
</field>
Whereas if i declare field as below,
<field name="destinationStationCode" class="java.lang.String">
<fieldDescription><![CDATA[FlightLog.FlightLog.destinationStationCode]]></fieldDescription>
</field>
I am not getting any value for the above code.
I tried using
<field name="destinationStationCode" class="java.lang.String">
<fieldDescription><![CDATA[FlightLog[FlightLog.destinationStationCode]]]></fieldDescription>
</field>
<field name="destinationStationCode2" class="java.lang.String">
<fieldDescription><![CDATA[FlightLog.FlightLog\\.destinationStationCode]]></fieldDescription>
</field>
How can i do this?
UPDATE
My jrxml is,
<?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="Test" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="062e3e2d-b648-49c7-b4a5-1d3c4fbdfc6b">
<queryString language="json">
<![CDATA[]]>
</queryString>
<field name="FlightLog" class="java.lang.Object">
<fieldDescription><![CDATA[FlightLog]]></fieldDescription>
</field>
<detail>
<band height="20" splitType="Stretch">
<textField isStretchWithOverflow="true">
<reportElement x="0" y="0" width="555" height="20" uuid="dc09b2c4-31b1-4458-8097-2e912e80b3a2"/>
<textFieldExpression><![CDATA[$F{FlightLog}.get("FlightLog.destinationStationCode")]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
UPDATE 2
I am not able to pass data to subreport, eg: I have a json like below,
"MaintLogResource":{
"MaintLogResource._lockVersion":"0",
"MaintLogResource.resource":[
{
"TEST" : "TEST1",
"ResourceType.resourceTimeHours":3.0,
"ResourceType.resourceDescription":"resourceDescription",
"ResourceType.resourceCount":2,
"ResourceType.resourceIdentifier":{
"ResourceIdentifier.resourceIdentifier":"resourceIdentifier",
"ResourceIdentifier.typeOfResourceIdentifier":"EQUIPMENT"
}
}
]
}
How do i pass it to sub report,
i tried like below,
((net.sf.jasperreports.engine.data.JsonDataSource)((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("MaintLogResource")).subDataSource("MaintLogResource.resource")
But the above code is giving me error,
net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :
Source text : ((net.sf.jasperreports.engine.data.JsonDataSource)((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("MaintLogResource")).subDataSource("MaintLogResource")
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:203)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:591)
at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:559)
at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:966)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:392)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:294)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:455)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2044)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:778)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:288)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:151)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:909)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:126)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:464)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:300)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:757)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:1003)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Caused by: net.sf.jasperreports.engine.JRException: No node available. Iterate or rewind the data source.
at net.sf.jasperreports.engine.data.JsonDataSource.subDataSource(JsonDataSource.java:445)
at net.sf.jasperreports.engine.data.JsonDataSource$subDataSource$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at Logbook_1434518442194_713295.evaluate(calculator_Logbook_1434518442194_713295:311)
at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:190)
... 19 more
How can i pass data to subreport?
UPDATE3
I am able to pass data to sub report like below,
new net.sf.jasperreports.engine.data.JsonDataSource(new ByteArrayInputStream($F{MaintLogResource}.get("MaintLogResource.resource").toString().getBytes()), "")
when i read a key with "." i cannot get the value, whereas if the key without dot i'm able to read the value eg: i'm able to get value for the key "TEST" but not for others.
destinationStationCode
is a key in FlightLog
and hence it is directly accessible. Same rule is applied on other keys, until any key have period sign, like FlightLog.destinationStationCode
, because period have its own meaning (access property on the object). And therefore it is not giving any value (You can verify by replacing period by any other characket, say "_", then all works).
To access this property, I suggest you to create an field FlightLog
of type Object
, like
<field name="FlightLog" class="java.lang.Object">
<fieldDescription><![CDATA[FlightLog]]></fieldDescription>
</field>
and access its properties like
<textField>
<reportElement x="0" y="0" width="555" height="29" uuid="afa65308-c0ae-4375-b8e5-99af4b69e02e"/>
<textFieldExpression><![CDATA[$F{FlightLog}.destinationStationCode]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="29" width="555" height="29" uuid="2009cbd3-7fb7-4d9e-8067-b03937aefcaa"/>
<textFieldExpression><![CDATA[$F{FlightLog}.get("FlightLog.destinationStationCode")]]></textFieldExpression>
</textField>
Hope this helps.
My files --
JSON
{
"FlightLog":{
"FlightLog.crewMembers":[
],
"destinationStationCode":"JPN",
"FlightLog.destinationStationCode":"IND",
"FlightLog.originStationCode":"IND",
"FlightLog._lockVersion":"0",
"FlightLog.flightNum":"123"
}
}
jrxml
<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="53cc1a16-1ec1-486c-82f6-51915fa4b069">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<field name="FlightLog" class="java.lang.Object">
<fieldDescription><![CDATA[FlightLog]]></fieldDescription>
</field>
<detail>
<band height="58" splitType="Stretch">
<textField>
<reportElement x="0" y="0" width="555" height="29" uuid="afa65308-c0ae-4375-b8e5-99af4b69e02e"/>
<textFieldExpression><![CDATA[$F{FlightLog}.destinationStationCode]]></textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="29" width="555" height="29" uuid="2009cbd3-7fb7-4d9e-8067-b03937aefcaa"/>
<textFieldExpression><![CDATA[$F{FlightLog}.get("FlightLog.destinationStationCode")]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With