If you add the "beans" option to the Java generator like this:

thrift --gen java:beans  file.thrift

Thrift will generate JavaBean style classes.

Properties of Generated JavaBean Classes

  1. All member fields are private.

  2. 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".
  3. 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.

  1. Setter methods update the corresponding __isset fields.

  2. Each member field has an "unset" method, like "unsetMyValue", which erases the field's value and updates the corresponding __isset field.

  3. Member fields whose corresponding __isset field is false 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.

ThriftJavaBeans (last edited 2009-09-20 23:47:13 by localhost)