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

Konstantin Shaposhnikov commented on THRIFT-3160:
-------------------------------------------------

No, this change shouldn't affect JSON and SimpleJSON thrift protocols.

It improves existing integration with Go encoding/json package. 

All generated types already have annotations supported by Go encoding/json 
package. E.g. 
{code}
type TestStruct struct {
        E          TestEnum          `thrift:"e,12" json:"e"`
}
{code}
Currently calling json.Marshal on an instance of this struct will produce JSON 
that will look like
{code}
{
  "e": 1
}
{code}

However if TestEnum implements TextMarshaller/TextUnmarshaller interfaces (from 
Go encoding package) as described then output from json.Marshal will look like:
{code}
{
  "e": "FIRST"
}
{code}

See http://golang.org/s/go12encoding for more.

> Make generated go enums implement TextMarshaller and TextUnmarshaller 
> interfaces
> --------------------------------------------------------------------------------
>
>                 Key: THRIFT-3160
>                 URL: https://issues.apache.org/jira/browse/THRIFT-3160
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Go - Compiler
>    Affects Versions: 0.9.2
>            Reporter: Konstantin Shaposhnikov
>
> This will make JSON encoder/decoders use string representation instead of 
> meaningless numbers.
> The new generated code will looks like:
> {code}
> func (p TestEnum) MarshalText() ([]byte, error) {
>       return []byte(p.String()), nil
> }
> func (p *TestEnum) UnmarshalText(text []byte) error {
>       x, err := TestEnumFromString(string(text))
>       *p = x
>       return err
> }
> {code}



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

Reply via email to