[
https://issues.apache.org/jira/browse/THRIFT-4747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16748310#comment-16748310
]
Renan Cakirerk commented on THRIFT-4747:
----------------------------------------
The `omitempty` tags were introduced here
https://issues.apache.org/jira/browse/THRIFT-3006, seems like 0.9.3.
> 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)