You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Mark Slee (JIRA)" <ji...@apache.org> on 2008/06/10 01:03:45 UTC

[jira] Commented: (THRIFT-33) Unset fields will still be serialized if they are primitives

    [ https://issues.apache.org/jira/browse/THRIFT-33?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12603722#action_12603722 ] 

Mark Slee commented on THRIFT-33:
---------------------------------

We originally did this to keep the library as lightweight as possible (i.e. to not require the use of get/set for all members). I agree that this is problematic when relying upon the isset feature to keep the structures lightweight over the wire -- and would endorse changing this as such.

This has actually already been implemented through the optional use of the -javabean generator flag. If you do this, then get/set methods, and an unset method, are generated for each field which keep the __isset up to date.

Also, if you specify the "optional" keyword on these fields, the javabean generated code will NOT send them over the wire when they are not set. Take a look at this code in the generator:

  for (f_iter = fields.begin(); f_iter != fields.end(); ++f_iter) {
    bool null_allowed = type_can_be_null((*f_iter)->get_type());
    if (null_allowed) {
      out <<
        indent() << "if (this." << (*f_iter)->get_name() << " != null) {" << endl;
      indent_up();
    }
    bool optional = bean_style_ && (*f_iter)->get_req() == t_field::T_OPTIONAL;
    if (optional) {
      out <<
        indent() << "if (this.__isset." << (*f_iter)->get_name() << ") {" << endl;
    }


> Unset fields will still be serialized if they are primitives
> ------------------------------------------------------------
>
>                 Key: THRIFT-33
>                 URL: https://issues.apache.org/jira/browse/THRIFT-33
>             Project: Thrift
>          Issue Type: Bug
>          Components: Compiler (Java), Library (Java)
>            Reporter: Bryan Duxbury
>
> Since primitive types (int, bool, byte, etc.) cannot be null in Java, the Java libraries will serialize "empty" values into their output. This is very bad when you have sparse Thrift structs with many possible fields and only one actually used. 
> The Isset logic appears to be partially implemented, but is apparently unused. It seems like the required action is using getters and setters and honoring the isset information appropriately.

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