Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-4011

Sets of Thrift structs generate Go code that can't be serialized to JSON

VotersStop watchingWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 0.11.0
    • Go - Compiler
    • None

    Description

      Consider the following structs:

      struct Foo {
        1: optional string foo
      }
      
      struct Bar {
        1: optional set<Foo> foos
      }
      

      This compiles into the following Go code:

      type Bar struct {
      	Foos map[*Foo]struct{} `thrift:"foos,1" db:"foos" json:"foos,omitempty"`
      }
      

      Even though the generated code has tags for JSON support, Bar can't be serialized to JSON:

      json: unsupported type: map[*Foo]struct {}
      

      One solution would be to use slices, not maps, for Thrift sets. Thoughts?

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            dcelasun Duru Can Celasun
            dcelasun Duru Can Celasun
            Votes:
            0 Vote for this issue
            Watchers:
            4 Stop watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment