Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
0.8
-
None
Description
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:
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; };
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).
Attachments
Issue Links
- duplicates
-
THRIFT-1297 Compiled javascript code does not write falsy values
- Closed