Giter VIP home page Giter VIP logo

Comments (7)

awalterschulze avatar awalterschulze commented on May 18, 2024

From awalterschulze on March 28, 2014 03:26:17

Does adding

option (gogoproto.enum_stringer_all) = true;

fix your issue?

from protobuf.

awalterschulze avatar awalterschulze commented on May 18, 2024

From jtolds on March 28, 2014 08:59:47

Yeah, that fixes it, but it seemed like the default behavior is supposed to match goprotobuf. I didn't expect to have to change any settings if I wanted to match the goprotobuf behavior.

from protobuf.

awalterschulze avatar awalterschulze commented on May 18, 2024

From awalterschulze on March 29, 2014 00:58:14

Ok but the default setting is

option (gogoproto.goproto_enum_stringer_all) = true;

and that matches the behaviour of goprotobuf.

Status: Done

from protobuf.

awalterschulze avatar awalterschulze commented on May 18, 2024

From jtolds on March 29, 2014 02:50:31

Given the following protocol buffer definition without any extensions,

message MyMessage {
enum MyEnum {
VAL1 = 1;
VAL2 = 2;
}
optional MyEnum setting = 1;
}

the following tests pass with goprotobuf but do not pass with gogoprotobuf.

package test

import (
"encoding/json"
"testing"
)

func TestString(t *testing.T) {
msg := &MyMessage{Setting: MyMessage_VAL1.Enum()}
if msg.Setting.String() != "VAL1" {
t.Fatal("string value expected")
}
}

func TestMarshalJSON(t *testing.T) {
data, err := json.Marshal(&MyMessage{Setting: MyMessage_VAL1.Enum()})
if err != nil {
t.Fatal(err)
}
var val interface{}
err = json.Unmarshal(data, &val)
if err != nil {
t.Fatal(err)
}
if (val.(map[string]interface{}))["setting"].(string) != "VAL1" {
t.Fatal("string value expected")
}
}

shouldn't they pass?

from protobuf.

awalterschulze avatar awalterschulze commented on May 18, 2024

From jtolds on March 29, 2014 02:51:42

Hopefully the provided test case is concrete enough, but my original ticket is poorly trying to explain that gogoprotobuf for some reason disables MarshalJSON on enums by default, and the only way to enable MarshalJSON for enums is to disable the default Stringer.

from protobuf.

awalterschulze avatar awalterschulze commented on May 18, 2024

From awalterschulze on March 29, 2014 03:25:40

I suspect you have not updated your goprotobuf, since October 2013 https://code.google.com/p/goprotobuf/source/detail?r=61664b8425f3e0e4371d4b56016b224b9d69cbbb This test fails on my February 2014 goprotobuf

from protobuf.

awalterschulze avatar awalterschulze commented on May 18, 2024

From jtolds on March 29, 2014 11:58:05

oh my goodness i'm so sorry for wasting your time. that's totally what happened

from protobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.