Web Service Data Adapters

This article shows how to retrieve JSON report data from a remote REST service using the built-in data adapter support from JasperReports Library and Jaspersoft Studio. Note that the same technique can be used to load XML, CSV or Excel data from remote URLs and is not specific to JSON data only.

Here we recreate the report shown in this demo, but do so without using the custom web service extension demonstrated there.

As opposed to the indicated demo, we are going to create a data adapter of type JSON File, which is a built-in type in JRL and JSS, instead of the custom data adapter type made available by that optional extension used in that demo.

The JSON data adapter allows specifying a remote URL instead of a local JSON file, as the source for the data.

When using an URL, the button next to the File/URL field changes from File to Options and thus allows setting request parameters and request headers for the HTTP call that will be made to the specified URL to retrieve the JSON data.

Once saved, the data adapter file would be available in the list of data adapters from which we can pick during the report creation wizard.

The report creation wizard will try connect to the remote URL and retrieve some data. It will show this data in the left panel and allows to select the node in the JSON object which represents the data source records for the report.

Once the data source record node selected, it will propose the selection of available fields that can be picked from the record node to use as report fields.

At the end of the report wizard, we obtain a JRXML file in which the main dataset has a JSONQL query and dataset fields that have special configuration properties which map them to specific nodes or attributes in the current record JSON node.

Adding some fields in the detail band helps complete the creation of a simple tabular report displaying records coming from JSON data loaded from a remote REST location.

Attached to this page are the data adapter file and the report template file used in this article.