Differences between revisions 3 and 4
Revision 3 as of 2008-07-25 16:25:02
Size: 1381
Editor: StuartSierra
Comment: Added description of Isset.
Revision 4 as of 2009-09-20 23:47:13
Size: 1385
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 25: Line 25:
`__isset` is necessary because Java primitives cannot be `null`. See discussion of [https://issues.apache.org/jira/browse/THRIFT-33 THRIFT-33]. `__isset` is necessary because Java primitives cannot be `null`. See discussion of [[https://issues.apache.org/jira/browse/THRIFT-33|THRIFT-33]].
Line 27: Line 27:
See the [http://developers.facebook.com/thrift/thrift-20070401.pdf Thrift Whitepaper] for more information on the Isset class. See the [[http://developers.facebook.com/thrift/thrift-20070401.pdf|Thrift Whitepaper]] for more information on the Isset class.

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)