thrift-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <>
Subject [jira] [Commented] (THRIFT-4011) Sets of Thrift structs generate Go code that can't be serialized to JSON
Date Sun, 15 Jan 2017 14:25:26 GMT


ASF GitHub Bot commented on THRIFT-4011:

Github user Jens-G commented on the issue: states that (as one would expect) a Thrift map is
defined as "A map of **strictly unique keys** to values. Translates to an STL map, Java HashMap,
PHP associative array, Python/Ruby dictionary, etc.". 
    Given that, I would say it could be one option to error, when the user inserts a duplicate.
On the other hand, in that case the better option could be to simply replace the current value.

    But **what should not happen is that serialized data come in with duplicated keys**. That
would be clearly an error as it is a violation of the rule above. In that case it might be
absolutely ok to return some kind of error.
    Re `panic()`, from my understanding of Go that's not the idiomatic way to go, since everything
form tha above is an easily recoverable error.
    Further reading:

> Sets of Thrift structs generate Go code that can't be serialized to JSON
> ------------------------------------------------------------------------
>                 Key: THRIFT-4011
>                 URL:
>             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
> {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

View raw message