nearing the end of my JSON rope...

Help
2008-06-04
2013-04-29
  • Andrew Hart
    Andrew Hart
    2008-06-04

    OK, so I implemented toJSONString for each of my *Info classes.  I'm generating the JSON string like this:

    JSONObject jo = JSONObject.fromObject( o, JmatJSONUtils.jsonConfig);
    return jo.toString();

    I *know* it's calling all of my toJSONString methods and that they're returning the desired string values because I'm dumping them out before I return from toJSONString.

    So, my console shows:

    08/06/04 13:32:15 IconInfoImpl.toJSONString()
    08/06/04 13:32:15 IconLocationInfoImpl.toJSONString()
    08/06/04 13:32:15 LatLonInfoImpl.toJSONString()
    08/06/04 13:32:15 LatLonInfoImpl.toJSONString() returns: {"latitude":"-1.2114","longitude":"14.6500"}
    08/06/04 13:32:15 IconLocationInfoImpl.toJSONString() returns: {"name":"CS1","day":0,"latLon":{"latitude":"-1.2114","longitude":"14.
    6500"}}
    08/06/04 13:32:15 IconInfoImpl.toJSONString() returns: {"id":1039,"name":"CS1","iconTypeName":"CASUALTY_SOURCE","notes":"","iconImag
    ePath":"/static/img/casualtysource.gif","editingAllowed":true,"groupIdList":[1006,1003],"locationInfoList":[{"name":"CS1","day":0,"l
    atLon":{"latitude":"-1.2114","longitude":"14.6500"}}]}

    OK, so that's how I think the JSON string should be... it looks like what I'm trying to achieve. ^^^^ Is how I want it to look.

    But, then the result that is getting passed as a result of calling JSONObject.toString() is producing this:

    08/06/04 13:32:15 Icon.getJsonString: {"id":1039,"name":"CS1","iconTypeName":"CASUALTY_SOURCE","notes":"","iconImagePath":"/static/img/casualtysource.gif","editingAllowed":true,"groupIdList":[1006,1003],"locationInfoList":[{"name":"CS1","day":0}]}

    And, so, as you can see, it's STRIPPING out the LatLonImpl toJSONString result.  Why would that be?  It's an instance of JSONString.  Why shoudn't I just call my toJSONString method directly then, instead of all this JSONObject.fromObject business?

     
    • aalmiray
      aalmiray
      2008-06-04

      Very strange indeed, which version of Json-lib are you using by the way?
      There is probably a hidden bug somewhere, could you provide a basic testcase that includes a sample of your domain classes?

      Thanks,
      Andres