0

I am facing a JSONException while using JSONArray.fromObject(jsonObj). I am not able to figure out the cause behind this exception. Can someone provide some sort of input as to why this error is occured?

 net.sf.json.JSONException: java.lang.reflect.InvocationTargetException
at net.sf.json.JSONObject._fromBean(JSONObject.java:987)
at net.sf.json.JSONObject.fromObject(JSONObject.java:168)
at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265)
at net.sf.json.JSONObject._processValue(JSONObject.java:2808)
at net.sf.json.JSONObject.processValue(JSONObject.java:2874)
at net.sf.json.JSONObject.setInternal(JSONObject.java:2889)
at net.sf.json.JSONObject.setValue(JSONObject.java:1577)
at net.sf.json.JSONObject._fromMap(JSONObject.java:1340)
at net.sf.json.JSONObject.fromObject(JSONObject.java:159)
at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265)
at net.sf.json.JSONArray._processValue(JSONArray.java:2514)
at net.sf.json.JSONArray.processValue(JSONArray.java:2539)
at net.sf.json.JSONArray.addValue(JSONArray.java:2526)
at net.sf.json.JSONArray._fromCollection(JSONArray.java:1057)
at net.sf.json.JSONArray.fromObject(JSONArray.java:123)
at net.sf.json.JSONArray.fromObject(JSONArray.java:105)
at net.sf.json.JSONArray$fromObject.call(Unknown Source)

The code is as below :

RESTClient restClient = new RESTClient(uri)
        Map<String, String> args = new HashMap<String,String>();
        args.put("responseContentType","ContentType.JSON");
        response = restClient.get(args)
        Object jsonObj = response?.getData()
        JSONArray jsonResp = JSONArray.fromObject(jsonObj)

The response that I get from REST service is as below :

[{"contract":"/api/v1/contracts/3","draw":"/api/v1/draws/5","drawName":null,"drawNumber":1,"id":5,"periodFrom":"2007-01-10","periodTo":"2007-02-10"}]
sunil
  • 9,541
  • 18
  • 66
  • 88
  • 1
    could you add the code you use to convert objects into json? – Francisco Spaeth Jul 03 '12 at 07:14
  • I have added the code and the exception is occurring on JSONArray.fromObject(jsonObj) line. – sunil Jul 03 '12 at 07:22
  • could you add a sample of the object instance as well? – Francisco Spaeth Jul 03 '12 at 07:23
  • I have added the REST service response. I am not sure if the value null is causing this issue. – sunil Jul 03 '12 at 07:26
  • Also, this seems to work properly in my local environment where it's deployed in Tomcat whereas on IBM Websphere portal server it's giving this exception. Any reasons for this behavior. I hope the web server should not be cause of reason behind this. – sunil Jul 03 '12 at 07:30

0 Answers0