Sunday, October 28, 2012

Using JSON-REST in ADF Mobile

In the current version of ADF Mobile the ADF DataControls ( URL and WS ) only supports SOAP and JSON-XML. But this does not mean we cannot use JSON. To handle JSON we can use the  RestServiceAdapter and JSONBeanSerializationHelper classes. The RestServiceAdapter will handle the Rest Service and JSONBeanSerializationHelper helps us converting JSON to Java.

I made a little ADF Mobile demo based on the Google Maps Geocoder and use this url to test it,+Mountain+View,+CA&sensor=true

with this as result

We start by creating an Url Connection with as value

Next is a new Class which can be used a managed bean or as a Java DataControl.

Here we do the following steps.

Create the RestServiceAdapter

RestServiceAdapter restServiceAdapter = Model.createRestServiceAdapter();

Use our Url Connection

HTTP Get operartion

Append the url with our search parameters

Send and wait for the result.
response = restServiceAdapter.send("");

Next step is using the JSON deserialization, here we will use the JSONBeanSerializationHelper class.
ServiceResult responseObject = (ServiceResult)jsonHelper.fromJSON(ServiceResult.class, response); 

ServiceResult class will be used as output, too bad I can't use generics or annotations to control the JSON deserialization. So I will use JSONArray in case of 1 or more results.

import oracle.adfmf.json.JSONArray;
public class ServiceResult {
   private String status;
   private JSONArray results;

JSONBeanSerializationHelper will look for attributes called .type and if that contains a class name then it will use that class for deserialization but I can't change the Google Maps service.

So I made my own Helper class which converts all JSONArray or JSONObject to the right class and attributes.

geoResult = GeocoderHelper.transformObject(responseObject).getResults();

Here is my the helper class

Now we are ready to use it in a managed bean or generate an ADF DataControl on it.
with this as result.

You can find my demo code on Github

Here the pictures of the application in the IPad emulator.


  1. Hey regarding this json web service call, how to ignore certificate warnings?

  2. Hi Edwin.!

    Need a help!
    i have a 30mb xml file which has 3 ubounded elements into into

    orderheaderdetils is just complex type
    order----- list----listof itemes

    in an order we get number of listitemnames(list)ubounded and listofitems(descriptions)ubounded

    the file size is increasing.. upto.. 30mb
    loading in bpel is itself consuming lot of time and processing to database is still more taking lot of time.

    and this cannot be controlled from senders end also..

    is there any idea that we can.. split before sending to bpel.

    coz we have many root elements we cannot batch it equally..

    so.. any help will be helpfull

    1. Hi,

      Can you use OSB and do a split join or try to do the same in a memory BPEL and use a for each parallel async invoke.