[
https://issues.apache.org/jira/browse/THRIFT-1499?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Henrique Mendonca closed THRIFT-1499.
-------------------------------------
Resolution: Duplicate
Assignee: Henrique Mendonca
> Generated javascript code doesn't properly write optional falsy values
> ----------------------------------------------------------------------
>
> Key: THRIFT-1499
> URL: https://issues.apache.org/jira/browse/THRIFT-1499
> Project: Thrift
> Issue Type: Bug
> Components: JavaScript - Compiler
> Affects Versions: 0.8
> Reporter: Darin Tay
> Assignee: Henrique Mendonca
> Labels: javascript
>
> The generated javascript code doesn't write out "falsy" values, which seems
> to be incorrect behavior for optional fields. Falsy values such as the empty
> string or the number 0 should be explicitly set, so that they are read out on
> the other end.
> The current behavior results in serialized data where fields are left unset,
> when really they should have been set to 0 (or the empty string).
> For example, the generated code for a .write looks like this:
> {code}
> DataRunFilter.prototype.write = function(output) {
> output.writeStructBegin('DataRunFilter');
> if (this.runType) {
> output.writeFieldBegin('runType', Thrift.Type.I32, 2);
> output.writeI32(this.runType);
> output.writeFieldEnd();
> }
> output.writeFieldStop();
> output.writeStructEnd();
> return;
> };
> {code}
> If runType (an enum) happens to be 0, the field won't be set at all and
> readers of the data will think it wasn't specified.
> Since the constructor explicitly nulls out all fields, it should be perfectly
> okay to instead test for null explicitly (e.g. " if (this.runType === null)
> {" above).
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira