Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Invalid
-
0.8
-
None
Description
The "optional" keyword is ignored in the generated javascript.
Given a thrift structure like :
>>
struct Contract {
1: SummaryContract summary,
3: string guarantees,
4: string options,
5: optional VehicleContract vehicle,
6: optional ResidenceContract residence,
7: optional HealthContract health,
}
>>
The thrift with JSONProtocol sent by the java server looks like :
>>
.."3":
}},"3":
{"str":"YAMAHA GUARANTEES"},"4":
{"str":"YAMAHA OPTIONS"},.."5":{"rec":{"1":
{"i32":2},"2":
{"str":"Yamaha"},"3":
{"str":"F6"},"4":{"str":"ARG-10-MESSI"}}..
>>
the ResidenceContract and HealthContract are structures are not sent by the java server.
But when this thrift stream is read by the javascript, the result is a json structure like :
>>
..,"description":"VEHICLE CONTRACT 1"},"guarantees":"YAMAHA GUARANTEES","options":"YAMAHA OPTIONS","vehicle":
,"residence":
{"type":0,"building":0,"rooms":0},"health":{"type":0}}..
>>
The ResidenceContract and HealthContract JSON objects are present but empty.
This is because the generated javascript is like:
>>
Contract = function(args){
this.summary = new SummaryContract()
this.guarantees = ''
this.options = ''
this.vehicle = new VehicleContract()
this.residence = new ResidenceContract()
this.health = new HealthContract()
>>
we see that the members are created by default in the constructor, even if they are "optional".