Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Deserialization of JSON from database

    I'm trying to save data arrived from RPCManager.sendRequest directly to the database (in VARCHAR type of column).
    The arrived data are being saved as a string : rpcManager.getData().toString();

    This works fine. However, when returning the same string from the database back to the client, the value is treated as a string and gets surrounded in double quotes.
    Is it possible to re-create java Map object from such JSON string?

    I tried :
    1) list = SQLTransform.toListOfMaps(rslt); This returns a list of maps for each column but those maps are still being treated as strings
    Code:
      rslt = stmt.executeQuery();
      List list = SQLTransform.toListOfMaps(rslt);
      Iterator<?> it =list.iterator();
      Map<?,?> map = (Map<?, ?>) it.next();
    
      RPCManager rpc = new RPCManager(request, response); 
      rpc.send(map);
    This last call is equivalent to rpc.getData().toString() and returns something like this to the client: //isc_RPCResponseStart-->[{status:0,data:"{myValues=[{ .... instead of //isc_RPCResponseStart-->[{status:0,data:{myValues=[{ .... (without surrounding data in "").

    2) JSTranslater
    3) sending string directly (rpcManager.send(json_str);
    Nothing works.

    Essentially, what would be the right way to convert from rpcManager.getData().toString() back to Java Map object?

    SmartClient 8.2 eval and 8.2 pro.

    thanks,
    - g
    Last edited by genev; 28 Dec 2011, 07:46.

    #2
    I'm sure it's a simple issue to solve but could you please point me in the right direction.
    Is there a way to convert rpcManager.getData().toString() back to Java Map object with smartclient 8.2 pro or with any earlier versions? Objects created from rpcManager.getData().toString() should be equivalent to those created from rpcManager.getData() call.
    Or do I have to rely on 3rd party parsers such as http://json.org/java/ ? I think that would defeat the purpose of using smartclient pro.
    The 8.2 javadocs (http://www.smartclient.com/docs/8.2/...doc/index.html) seem to be incomplete, I can't find info on some of the classes in the com.isomorphic.js package and some methods that may be relevant, such as fromJS().
    What am I missing, please help.

    thanks,
    - gene

    Comment


      #3
      Try using the JavaScript "eval" function to convert it to an object

      Comment


        #4
        Thank you for your reply. Actually, I mentioned the client-side processing just to illustrate the point.
        My flow is this:
        1. Get data from the client via rpc.getData() call.
        2. Convert the data to rpc.getData().toString() and store in the DB. I don't want to serialize java objects (Maps in this case) directly.
        3. Then I need to be able to retrieve data from the DB and create Java objects that would be identical to the java objects returned by the rpc.getData() call.
        The issue is that java objects created from the JSON string on the server side are not equivalent (reflective/transitive/symmetric/etc) to those created from the client-side request. This means that different server-side logic must be implemented to deal with the same objects arriving from the client and from the database.
        I'm not hung up on JSON, storing client-side data in XML would work too assuming it satisfies the equivalence criteria.
        Surprisingly, I'm unable to find a solution for either ways of implementing this and JavaDocs are incomplete. So my guess is that it's either not implemented in Smartclient 8.2 or there is a bug in the existing implementation.

        Using JSTranslater's fromJS() method results in the following exception:
        Encountered "=" at line 1, column 9.
        Was expecting:
        ":" ...

        ERROR: com.isomorphic.js.UnconvertableException: parse failure:
        com.isomorphic.js.parser.ParseException: Encountered "=" at line 1, column 9.

        I guess this method is designed to deal with pure JavaScript and not with JSON.
        I'm afraid I'd have to resort to implementing client and server side data parsing myself instead of relying on Smartclient APIs.

        Comment

        Working...
        X