You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2017/01/15 10:06:26 UTC

[jira] [Commented] (THRIFT-4011) Sets of Thrift structs generate Go code that can't be serialized to JSON

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

ASF GitHub Bot commented on THRIFT-4011:
----------------------------------------

GitHub user dcelasun opened a pull request:

    https://github.com/apache/thrift/pull/1156

    THRIFT-4011 Use slices for Thrift sets

    As discussed in [THRIFT-4011](https://issues.apache.org/jira/browse/THRIFT-4011), this commit changes the Go generator to use slices, instead of maps for Thrift sets.
    
    I've specifically didn't touch the Go library since there was no agreement on panicking for duplicates. We have three options:
    
    1. Leave it as is and add documentation stating deduplication is the caller's responsibility.
    2. Silently deduplicate before serialization.
    3. panic on duplicates.
    
    2 and 3 probably requires [`reflect.DeepEqual`](https://golang.org/pkg/reflect/#DeepEqual), which is not ideal.
    
    @Jens-G Thoughts?

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/dcelasun/thrift master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/thrift/pull/1156.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1156
    
----
commit 0e2e8c0b041300dafff641e19848a1e46df32bc6
Author: D. Can Celasun <dc...@gmail.com>
Date:   2017-01-15T09:53:19Z

    THRIFT-4011 Use slices for Thrift sets
    
    This commit changes the Go generator to use slices, instead of maps for Thrift sets.

----


> Sets of Thrift structs generate Go code that can't be serialized to JSON
> ------------------------------------------------------------------------
>
>                 Key: THRIFT-4011
>                 URL: https://issues.apache.org/jira/browse/THRIFT-4011
>             Project: Thrift
>          Issue Type: Bug
>          Components: Go - Compiler
>            Reporter: Can Celasun
>
> Consider the following structs:
> {code}
> struct Foo {
>   1: optional string foo
> }
> struct Bar {
>   1: optional set<Foo> foos
> }
> {code}
> This compiles into the following Go code:
> {code}
> type Bar struct {
> 	Foos map[*Foo]struct{} `thrift:"foos,1" db:"foos" json:"foos,omitempty"`
> }
> {code}
> Even though the generated code has tags for JSON support, Bar can't be serialized to JSON:
> {code}
> json: unsupported type: map[*Foo]struct {}
> {code}
> One solution would be to use slices, not maps, for Thrift sets. Thoughts?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)