You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "James E. King III (JIRA)" <ji...@apache.org> on 2019/01/22 03:26:00 UTC
[jira] [Resolved] (THRIFT-4747) The 'omitempty' tag should not be
appended to optional fields that have a default value
[ https://issues.apache.org/jira/browse/THRIFT-4747?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
James E. King III resolved THRIFT-4747.
---------------------------------------
Resolution: Fixed
Assignee: James E. King III
Fix Version/s: 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
> Assignee: James E. King III
> Priority: Major
> Fix For: 0.13.0
>
> Time Spent: 20m
> 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)