freitas_tiago Posted October 7, 2021 Share Posted October 7, 2021 Hello dear friends.I'm using jasperSoft Studio 6.17.0 and I'm struggling with the following problem:I have an input string parameter that , in fact, is a json structure. I have no data adapter, and I need to populate my report with the content of that parameter. I know how to do with a json file, but tried many things with json input as a string parameter.{person: {name: "john", age: '22'}, car: {name: 'BMW', model: 'X3'}}I haven't found any example in the net, so does anybody knows how to do that? Thanks Link to comment Share on other sites More sharing options...
narcism Posted October 8, 2021 Share Posted October 8, 2021 You could checkout my post on stack overflow, here: https://stackoverflow.com/a/37441567/5882963. It covers your case also. It starts with the XML solution then, towards the end, the JSON solution is presented. Link to comment Share on other sites More sharing options...
freitas_tiago Posted October 8, 2021 Author Share Posted October 8, 2021 Thanks for your answer, but I made a full copy of your code but the report return only one null:"<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.17.0.final using JasperReports Library version 6.17.0-6d93193241dd8cc42629e188b94f9e0bc5722efd --><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="Atestado" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="25dce969-32ae-4951-b8c6-6e55c8817291"> <parameter name="jsonString" class="java.lang.String"> <defaultValueExpression><![CDATA["{"a": [ {"b": { "val": "val1"}}, {"b": { "val": "val2" }}]}"]]></defaultValueExpression> </parameter> <parameter name="JSON_INPUT_STREAM" class="java.io.InputStream"> <defaultValueExpression><![CDATA[new java.io.ByteArrayInputStream($P{jsonString}.getBytes("UTF8"))]]></defaultValueExpression> </parameter> <queryString language="JSON"> <![CDATA[a.b]]> </queryString> <field name="value" class="java.lang.String"> <fieldDescription><![CDATA[val]]></fieldDescription> </field> <columnHeader> <band height="31" splitType="Stretch"> <staticText> <reportElement x="150" y="0" width="100" height="30" uuid="b33a123d-8987-4da4-b21b-1f9ccc50e92d"/> <text><![CDATA[value]]></text> </staticText> </band> </columnHeader> <detail> <band height="30" splitType="Stretch"> <textField> <reportElement x="150" y="0" width="100" height="30" uuid="14c51219-5ce2-47ce-abb9-71bc11a6f28c"/> <textFieldExpression><![CDATA[$F{value}]]></textFieldExpression> </textField> </band> </detail></jasperReport>"The value I inserted in the prompt was:{"a": [ {"b": { "val": "val1"}}, {"b": { "val": "val2" }}]}and{"a": [ {"b": { "val": "val1"}}, {"b": { "val": "val2" }}]}The result was the same: nullAny idea? Link to comment Share on other sites More sharing options...
narcism Posted October 8, 2021 Share Posted October 8, 2021 Try previewing with "Don't use a Data Adapter" option. Picking other data adapter will bypass the JSON_INPUT_STREAM parameter Link to comment Share on other sites More sharing options...
freitas_tiago Posted October 8, 2021 Author Share Posted October 8, 2021 That's it! It worked.Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now