[ 
https://issues.apache.org/jira/browse/THRIFT-4747?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

James E. King III updated THRIFT-4747:
--------------------------------------
    Fix Version/s:     (was: 0.13.0)

> The 'omitempty' tag should not be appended to optional fields that have a 
> default value
> ---------------------------------------------------------------------------------------
>
>                 Key: THRIFT-4747
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4747
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Go - Compiler
>            Reporter: Renan Cakirerk
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> When an optional field has a default value, the field won't have a pointer 
> type anymore but will still keep the `omitempty` tag.
> For example the following thrift file:
> {code:java}
> struct Node {
>     1: optional bool is_live = false
> }
> {code}
> Will be generated as:
> {code:java}
> type Node struct {
>     IsLive bool `thrift:"is_live,1" db:"is_live" json:"is_live,omitempty"`
> }
> {code}
> If you create an instance of this struct and set the value to `false`:
> {code:java}
> node := Node{IsLive: false}{code}
> And then json.Marshal `node`, the output will be:
> {code:java}
> {}
> {code}
> Where it must be:
> {code:java}
> {is_live: false}
> {code}
> This happens because Go Marshal will ignore `zero values` if there is an 
> `omitempty` tag attached to it.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to