You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Larregoity (Closed) (JIRA)" <ji...@apache.org> on 2012/03/28 15:00:28 UTC

[jira] [Closed] (THRIFT-1546) Generated javascript ignores the "optional" keyword

     [ https://issues.apache.org/jira/browse/THRIFT-1546?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Larregoity closed THRIFT-1546.
------------------------------

    Resolution: Invalid

Sorry, was looking at javascript generated by 0.5 compiler.
Fixed in 0.8
                
> Generated javascript ignores the "optional" keyword
> ---------------------------------------------------
>
>                 Key: THRIFT-1546
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1546
>             Project: Thrift
>          Issue Type: Improvement
>          Components: JavaScript - Compiler
>    Affects Versions: 0.8
>            Reporter: Larregoity
>            Priority: Minor
>              Labels: javascript, optional
>
> 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":{"str":"VEHICLE CONTRACT 1"}}},"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":{"type":2,"brand":"Yamaha","model":"F6","inmatriculation":"ARG-10-MESSI"},"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".

--
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