If you add the "beans" option to the Java generator like this:
thrift --gen java:beans file.thrift
Thrift will generate WikiPedia:JavaBean style classes.
Properties of Generated JavaBean Classes
- All member fields are
private
. - All member fields have mixed-cased getter and setter methods. For example, if the field is named "myValue", the methods will be "getMyValue" and "setMyValue".
- Getter methods for boolean fields begin with "is", for example, "isMyValue".
The Nested Isset Class
Each generated Bean class has public field named __isset
, which is an instance of a nested class named Isset
.
Each member field in the parent class has a corresponding public boolean
field in the Isset
class with the same name.
- Setter methods update the corresponding
__isset
fields. - Each member field has an "unset" method, like "unsetMyValue", which erases the field's value and updates the corresponding
__isset
field. - Member fields whose corresponding
__isset
field isfalse
will be omitted from the serialized output.
__isset
is necessary because Java primitives cannot be null
. See discussion of THRIFT-33.
See the Thrift Whitepaper for more information on the Isset class.