IC5Notice: We have upgraded developerWorks Community to the latest version of IBM Connections. For more information, read our upgrade FAQ.
Topic
  • 3 replies
  • Latest Post - ‏2011-01-19T18:43:26Z by SystemAdmin
SystemAdmin
SystemAdmin
9029 Posts

Pinned topic Looking for simple example using REST call builder and JSON format

‏2011-01-14T13:21:20Z |
Hi,
I am using REST call builder to call a REST service (running on a BAM Server). I am getting response data in JSON format. I want to display it in tabular format. I am not able to display it. Can anyone give a simple example using REST call builder along with Dojo Data Store and Dojo Data Grid preferably? Many thanks in advance.
Updated on 2011-01-19T18:43:26Z at 2011-01-19T18:43:26Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    9029 Posts

    Re: Looking for simple example using REST call builder and JSON format

    ‏2011-01-19T07:06:35Z  
    Please see attached file containing example JSON data. I am getting this data from REST Service. I want to display this JSON data in tabular format. Can anyone please give me small example to display this data in a tabular format? Many thanks in advance.
  • SystemAdmin
    SystemAdmin
    9029 Posts

    Re: Looking for simple example using REST call builder and JSON format

    ‏2011-01-19T16:35:10Z  
    Please see attached file containing example JSON data. I am getting this data from REST Service. I want to display this JSON data in tabular format. Can anyone please give me small example to display this data in a tabular format? Many thanks in advance.
    The short answer is that we don't offer an easy way to do it. PageAutomation expects XML data, ideally described by a schema. I was a little chagrined to see that we don't offer a converter. There's an XML to JSON builder, but it is not intended for a purely on-the-server conversion. It certainly wouldn't be rocket science to make a builder which does this, but we haven't made one.

    So the first option would be to pester whoever owns the REST service and try to get them to offer a version of it that returns XML.

    If that isn't possible, then you will have to do it yourself, I'm afraid. I suggesting putting it in a separate model and making your own service definition and service operation builders. Make a method which takes the same arguments, calls your REST service, does the conversion to IXml, and returns your constructed IXml. Hand-create a schema that describes Point the operation at this method with the hand-created schema.

    Note: If you aren't adept at XSD then an easy way to create a schema is to make a variable with some sample data (include a second copy of anything that repeats) and point a Simple Schema Generator builder at it. Then right-click the SSG builder and convert it to be a schema builder. It will create the Schema builder initialized with the created schema, which you then can tweak with proper data types and the like.

    The IXml interface is well-documented. You'll want to use that and the XmlUtil class to create the top level.

    Sorry I haven't a better answer.
  • SystemAdmin
    SystemAdmin
    9029 Posts

    Re: Looking for simple example using REST call builder and JSON format

    ‏2011-01-19T18:43:26Z  
    Please see attached file containing example JSON data. I am getting this data from REST Service. I want to display this JSON data in tabular format. Can anyone please give me small example to display this data in a tabular format? Many thanks in advance.
    Actually the REST Service Call builder does have a JSON converter built-in as one of the Auto conversion types. I was able to plug in your JSON sample and it did get converted to XML, BUT the JSON data appears to contain a list of lists where all the fields have the same name(Metric_Data) and are described in another part of the document using the Metric_ID_Array fields. There's no way for Page Automation to do anything reasonable with such a structure. However the REST Service Call builder does allow you to specify your own Restructure Handler so you can write some code to assist in the conversion of JSON to XML.

    Here are some pointers to classes on the WPF Java doc to get you started.
    com.bowstreet.builders.webapp.methods.RestructureFeedData
    com.bowstreet.builders.webapp.methods.JsonRestructureHandler
    com.bowstreet.util.JSON2XMLHandlerImpl
    Basically you can create your own restructure handler that extends JsonRestructureHandler. In your restructure handler you can take over the getConversionHandler() method which must return a JSON2XMLHandler. You can create your own version of a JSON2XMLHandler by extending the com.bowstreet.util.JSON2XMLHandlerImpl class. In your JSON2XMLHandler class you can take over the base class methods as needed.

    Tom