You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Renan Cakirerk (JIRA)" <ji...@apache.org> on 2019/01/22 01:19:00 UTC

[jira] [Comment Edited] (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:comment-tabpanel&focusedCommentId=16748302#comment-16748302 ] 

Renan Cakirerk edited comment on THRIFT-4747 at 1/22/19 1:18 AM:
-----------------------------------------------------------------

Here's how to setup the thrift build environment on MacOS and test my changes. Might be useful for someone.
h1. 1.Install Dependencies
h2. 1.1.Use Latest Node
{code:java}
nvm use node{code}
h2. 1.2.Install Composer
{code:java}
curl -sS https://getcomposer.org/installer | php
chmod +x composer.phar 
mv composer.phar /usr/local/bin/composer{code}
h2. 1.3.Install Boost and Bison
{code:java}
brew install boost
brew install bison
echo 'export PATH="/usr/local/opt/bison/bin:$PATH"' >> ~/.zshrc # or .bashrc
source ~/.zshrc{code}
h2. 1.4.Install OpenSSL

I already had it installed but if you don't have it, it's probably `brew install openssl` followed by a couple of linking hacks you can find on stackoverflow.
h1. 2.Clone & Compile
{code:java}
git clone https://github.com/apache/thrift.git
cd thrift.git

./bootstrap.sh
./configure --with-boost=/usr/local/opt/boost --with-openssl=/usr/local/opt/openssl

make {code}
h1. 3.Modify Code & Run Go Tests
{code:java}
make{code}
{code:java}
cd lib/go
make check  # Runs Go tests only
{code}
h1. 4.Manually Compile a Thrift File and Check the Output
{code:java}
./compiler/cpp/thrift --gen go -r ./lib/go/test/GoTagTest.thrift{code}
{code:java}
vim gen-go/gotagtest/GoTagTest.go
{code}


was (Author: bit2pixel):
Here's how to setup the thrift build environment on MacOS and test my changes. Might be useful for someone.

 
h1. 1.Install Dependencies
h2. 1.1.Use Latest Node
 
{code:java}
nvm use node{code}
h2. 1.2.Install Composer
 
{code:java}
curl -sS https://getcomposer.org/installer | php
chmod +x composer.phar 
mv composer.phar /usr/local/bin/composer{code}
h2. 1.3.Install Boost and Bison

 
{code:java}
brew install boost
brew install bison
echo 'export PATH="/usr/local/opt/bison/bin:$PATH"' >> ~/.zshrc # or .bashrc
source ~/.zshrc{code}
 
h2. 1.4.Install OpenSSL

I already had it installed but if you don't have it, it's probably `brew install openssl` followed by a couple of linking hacks you can find on stackoverflow.
h1. 2.Clone & Compile

 
{code:java}
git clone https://github.com/apache/thrift.git
cd thrift.git

./bootstrap.sh
./configure --with-boost=/usr/local/opt/boost --with-openssl=/usr/local/opt/openssl

make{code}
 
 
h1. 3.Modify Code & Run Go Tests

 
{code:java}
make{code}
{code:java}
cd lib/go
make check  # Runs Go tests only
{code}
 
 
h1. 4.Manually Compile a Thrift File and Check the Output

 
{code:java}
./compiler/cpp/thrift --gen go -r ./lib/go/test/GoTagTest.thrift{code}
{code:java}
vim gen-go/gotagtest/GoTagTest.go
{code}
 
 

> 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
>             Fix For: 0.13.0
>
>          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)