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

                 Key: THRIFT-543
                 URL: https://issues.apache.org/jira/browse/THRIFT-543
             Project: Thrift
          Issue Type: Improvement
          Components: Compiler (Java)
         Environment: all platforms
            Reporter: Chengdu Huang


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();
 }


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to