Announcement

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

    Problem in serialization of "multiple" typed fields with RestDataSource

    Hello,

    We have several endpoints in our system which for we are using RestDataSource variants for making requests. We have been observing problems when sending requests with fields which have been declared as "multiple". When these values are serialized and the value is not set (for example on a DynamicForm) the value is sent as if it would be set as an empty string. This really is not SmartGWT version specific, we've seen this behaviour for a while but currently, we're using a 5.0p 2016-01-07 nightly build. We are pretty sure this did not happen with really dated builds (such as 3.x) but we haven't tested them anymore as we've been in 4.x and 5.x branches for a while.

    Some simple code to reproduce:

    Code:
                    RestDataSource r = new RestDataSource();
                    OperationBinding ob = new OperationBinding(DSOperationType.ADD, "none");
                    ob.setDataProtocol(DSProtocol.POSTMESSAGE);
                    r.setOperationBindings(ob);
    
                    DataSourceTextField tf = new DataSourceTextField("test");
                    tf.setMultiple(true);
                    r.setFields(tf);
    
                    Record rec = new Record();
                    // simulate for example a SelectItem on a form, it gets set this way when no values are chosen
                    rec.setAttribute("test", (String[])null);   
                    r.addData(rec);
    Run the above code and set a breakpoint to RestDataSource.js's transformRequest to inspect the XML request which is serialized:

    Code:
    <request>
      <data>
        <test>
          <value></value>
        </test>
      </data>
      ...
    </request>
    We'd expect the element to be <test/> or not sent at all. We have all kinds of dirty hacks in our codebase to go around this problem and this popups for us from time to time. We've also tried patching the xmlSerialize-logic in RestDataSource's transformRequest function to go around this problem with no real solution.

    As we've debugged this, the problem lies at the end of xmlSerializeFields function of DataSource:

    Code:
        xmlSerializeFields : function (data, flags, indent) {
    
        ...
            // in flatData mode, we don't delete fields that we've output, because we don't
            // write out undeclared data at the end
            if (!flatData && data[fieldName] != null) delete data[fieldName];
        }
    
        // if there's any data left, tack them on the end, but *not* if this DataSource came
        // form XML Schema, in which case the extra data is sure to be invalid
        if (!flatData && !isc.isA.Schema(this)) {
            for (var fieldName in data) {
                output.append(this.xmlSerializeField(fieldName, data[fieldName], flags, indent));
            }
        }
    
        return output.release(false);
    },
    What happens is, that for null or undefined values, they don't get deleted from the data-array and at the end, they get appended to the output with xmlSerializeField function which handles null values for multiple fields bit strangely.

    Question: Is this intentional ? Is there a way to go around this problem, by for example fooling the framework that our rest data sources are "XML Schema derived" - or something ?

    I'd also like to point out that this is not the only place where this serialization logic causes headache for us. We have some custom xmlSerialize calls too to generate XML and as expected, this behaviour is seen there too.

    Thanks a lot,
    Marko
Working...
X