Announcement

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

    Side-effects of com.smartgwt.client.util.JSON.encode(jsObj)

    Hello,

    I would expect that JSON.encode(jsObj) function that does not modify the object that is passed as a parameter (e.g. it is a function without side-effects).

    Using below code I can confirm that some JSON properties are removed from jsObj after calling JSON.encode(jsObj).

    To prove this behavior, I created two string representations of the jsObj, that are encoded using pure native JavaScript stringify() function - BEFORE call and AFTER call.
    Then I compared these two strings (BEFORE and AFTER) strings and found they are different.
    In this case, properties with names like "_recordComponents_isc_CalculationResultGrid" are removed!

    Code:
    GWT.log("BEFORE:" + stringify(jsObj));
    String encodedString = JSON.encode(jsObj);
    GWT.log("AFTER :" + stringify(jsObj)); 
     private final static native String stringify(JavaScriptObject obj)  /*-{ return JSON.stringify(obj); }-*/;
    Properties highlighted in red are removed from jsObj AFTER calling JSON.ecnode(jsObj):

    Code:
     
     "outputs": [   {     "resultName": "Ref",     ...     "_recordComponents_isc_CalculationResultGrid_0": {        "warnings": {          "isNullMarker": true,          "$669": "isc_CalculationResultGrid_0_body",          "$81x": 1         },    ... }
    Isn't this bug?

    Is it described somewhere why this happens?

    In our case this caused some bug that I can workaround by first creating clone of the jsObj.

    Milan

    #2
    We wouldn't expect this, and we don't see it in basic testing, using your sample snippet with an arbitrary JSO - it's not clear which attributes you're saying are removed (nothing in red) - is it properties that are nested several layers deep, for example, or that have keys prefixed with $?

    We expect encode() to simply skip some (internal, eg) properties, not to make any changes to the object itself.

    If you can provide a complete test we can run to see the issue, including a full JSO that you're seeing problems with, then we can take another look.
    Last edited by Isomorphic; 27 Nov 2017, 00:36.

    Comment


      #3
      The "diff" is on the screenshot here:
      Attached Files

      Comment


        #4
        We've tested this again, as best we can without a test-case - and we still see no issues.

        JSON.encode() has no logic to remove properties from an object, so it's difficult to see how a call to it could result in this situation.

        Showing a diff doesn't really help us in finding out if there's a bad behavior here - the object you show in the diff appears to be save data from a ListGrid, and there are indeed codepaths that might remove internal ListGrid attributes (like the one you specified) from save-data before sending it to the server - that would be expected behavior, though, since we don't want to send arbitrary widget metadata in save requests.

        Please put together a standalone test-case we can run to see the failure - without that, we don't really know where that object is coming from, or what's happening to it before/between your JSON calls.

        Comment

        Working...
        X