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

Generate normal style java files should respect the "optional" keyword when serializing

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.2
    • Component/s: Java - Compiler
    • Labels:
      None
    • Environment:

      all platforms

    • Patch Info:
      Patch Available

      Description

      struct UserDataContent {
      1: i32 id,
      2: optional i32 value,
      }

      Java file generated by "thrift --gen java " doesn't seem to respect
      the "optional" keyword:

      public void write(TProtocol oprot) throws TException

      { validate(); oprot.writeStructBegin(STRUCT_DESC); oprot.writeFieldBegin(ID_FIELD_DESC); oprot.writeI32(this.id); oprot.writeFieldEnd(); oprot.writeFieldBegin(VALUE_FIELD_DESC); oprot.writeI32(this.value); oprot.writeFieldEnd(); oprot.writeFieldStop(); oprot.writeStructEnd(); }

      However, java file generated using "thrift --gen java:beans" looks
      correct to me:
      public void write(TProtocol oprot) throws TException {
      validate();

      oprot.writeStructBegin(STRUCT_DESC);
      oprot.writeFieldBegin(ID_FIELD_DESC);
      oprot.writeI32(this.id);
      oprot.writeFieldEnd();
      if (isSetValue())

      { oprot.writeFieldBegin(VALUE_FIELD_DESC); oprot.writeI32(this.value); oprot.writeFieldEnd(); }

      oprot.writeFieldStop();
      oprot.writeStructEnd();
      }

        Attachments

          Activity

            People

            • Assignee:
              chengdu Chengdu Huang
              Reporter:
              chengdu Chengdu Huang
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified