Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1546

Generated javascript ignores the "optional" keyword

    XMLWordPrintableJSON

Details

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

      {"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".

      Attachments

        Activity

          People

            Unassigned Unassigned
            alarregoity Larregoity
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: