[
https://issues.apache.org/jira/browse/THRIFT-4011?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15768040#comment-15768040
]
Can Celasun commented on THRIFT-4011:
-------------------------------------
[~jensg] I could send a patch that uses slices for Thrift's sets and lists, but
that would be backwards incompatible with all the generated Go code out there.
But this would be for master, not 0.9.3, so maybe that's acceptable. What do
you think? If that is indeed acceptible I'm willing to work on a patch.
Another concern is that, while slices are good for representing lists, Go
doesn't have any data structures for sets. For emulating sets, I think we have
2 options:
- Use map[X]struct{} for sets where X is NOT a pointer. This would ensure
uniqueness, but it wouldn't solve the JSON issue. json.Marshal would succeed,
but the output would be wrong.
- Use slices. In the Thrift library, before serialization, iterate through the
slice and panic if there are duplicates.
So the only real option is #2. Thoughts?
> Sets/Lists 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 Thirft sets ands lists.
> Thoughts?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)