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

James Haggerty commented on THRIFT-1528:
----------------------------------------

As Josh mentioned, there are significant advantages to not serialising default 
values.

Say you have a large Struct with a lot of boolean options in it, but 90% of the 
time those options don't move from their defaults (normally False). To get 
around this issue, you could try to implement booleans defaulting to False by 
using optional without a default (i.e. counting !isset/null/None as false). But 
abusing things like this means you can't distinguish between fields that are 
null because they are not filled in and fields that are null because that 
represents false... which is a pain when you're custom encoding the struct as 
JSON for the end user.

IMO it doesn't make much sense to have 'optional with default' unless this 
behaviour is supported.

> Inconsistency in optional fields between Java/C# and python
> -----------------------------------------------------------
>
>                 Key: THRIFT-1528
>                 URL: https://issues.apache.org/jira/browse/THRIFT-1528
>             Project: Thrift
>          Issue Type: Bug
>          Components: Python - Compiler
>    Affects Versions: 0.8
>            Reporter: Stefan Gmeiner
>             Fix For: 1.0
>
>
> If a struct contains optional fields with default values the generated python 
> code serialize differently than Java or C# code.
> In Java or C# optional fields are only serialized if a field was set by the 
> client. If not the field is omited during serialization. This is possible 
> because C#/Java maintains for each field a 'isset'-boolean which records if a 
> field was set or not.
> However the generated python code does not have such a 'isset'-structure. It 
> writes every field which is not equal None. As the constructor initialize the 
> optional fields with their default value, these fields are written whether 
> they are set or not.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to