I have a simple thrift file:
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();
}
My question is that why "normal" java style files should be different
from "beans" style files in terms of handling optional fields?
The change is introduced in rev665308 (t_java_generator.cc:1105).
Thanks,
Chengdu