4

I have a message from thrift that I would like to be able to serialize into and out of json, but I don't want the generated json keys to match what is in the generated go code.

Is there a way to control what annotations are attached to the struct in the go code that thrift generates?

1 Answer 1

4

Scratch my previous answer - it's undocumented, but it IS possible, I found it by reading the compiler code. Bah.

But anyway, in thrift's master (1.0-dev), here's how it's done - using a go.tag annotation.

This piece of thrift code:

struct foo {
  1: string bar (go.tag = "json:\"baz\" yo:\"dawg\""),
  2: string bang
}

Generates the following Go code:

type Foo struct {
        Bar  string `thrift:"bar,1" json:"baz" yo:"dawg"`
        Bang string `thrift:"bang,2" json:"bang"`
}
Sign up to request clarification or add additional context in comments.

6 Comments

Appreciate your patch proposal.
@JensG I'm assuming this is sarcastic, but I would be glad to document this stuff, where would you recommend to do it?
Not more than Bah ;-) A good place is the language-specific README which can be found in the normal repo under /lib/go/README.md. We accept patches and pull requests - thank you!
Will do. Oh, and I've already contributed a couple of patches to thrift :)
Did you make a pull request Not_a_Golfer? I ran into the same issue you did, and I didn't see any documentation in the readme so I made this pull request: github.com/apache/thrift/pull/1053
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.