Jump to content
We've recently updated our Privacy Statement, available here ×
  • Web Service Data Adapters


    teodord
    • Product: JasperReports® Library

    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.

    captura_de_ecran_din_2018_10.04_la_10_05_47.png.619cc7dd8ea1540b2cdc3f3fb62b3790.png

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

    captura_de_ecran_din_2018_10.04_la_15_27_09.png.7277e5bb8ae1a47a0dcb293da8b2566b.png

    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.

    captura_de_ecran_din_2018_10.04_la_15_27_23.png.c4fc41b0865b2709e3c3b675c3ea23d5.png

    captura_de_ecran_din_2018_10.04_la_15_27_36.png.a87469cd68ce81da3c1845ffbbf84e63.png

    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.

    captura_de_ecran_din_2018_10_04_la_15_36_04.png.6fb340e1bdce99a2e301d47d994301a1.png

    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.

    captura_de_ecran_din_2018_10.04_la_15_36_31.png.1c26edd49d673c5c968fb1fb274817dc.png

    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.

    captura_de_ecran_din_2018_10.04_la_15_36_56.png.ab533dc10df226744f0f7b3257869b6f.png

    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.

    1538656712199.jpg.6d800c9bb50625699a4a9a5f2d3ba851.jpg

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

     

    noaadataadapter.xml

    noaareport.jrxml


    User Feedback

    Recommended Comments

    Great, but how to change parameters for the URL of the JSON File adapter ?

    For exemple, how to call report with diferents ID parameter with jaspersoft server REST API ? :

    Report one : /jasperserver/rest_v2/reports/reports/MY_REPORT.PDF?ID=ONE
    Report two : /jasperserver/rest_v2/reports/reports/MY_REPORT.PDF?ID=TWO

    For calling JSON File adapter with this "ID" parameter :

    One : JSON_File_adapter_base_remote_URL?ID=ONE
    Two : JSON_File_adapter_base_remote_URL?ID=TWO

    Link to comment
    Share on other sites



    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 account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...