Skip to content

Commit 9ebc6c4

Browse files
committed
jsonpb: Disable Marshaler.EnumsAsString; it is now the default.
Later this week I will remove EnumsAsString entirely.
1 parent 0ea3c03 commit 9ebc6c4

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

jsonpb/jsonpb.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ type Marshaler struct {
6262
// Whether to render enum values as integers, as opposed to string values.
6363
EnumsAsInts bool
6464

65-
// Use string values for enums (as opposed to integer values)
66-
// This is DEPRECATED and will become the default.
65+
// EnumsAsString is DEPRECATED and does nothing.
6766
EnumsAsString bool
6867

6968
// A string to indent each level by. The presence of this field will
@@ -192,7 +191,7 @@ func (m *Marshaler) marshalValue(out *errWriter, v reflect.Value,
192191

193192
// Handle enumerations.
194193
protoInfo := structField.Tag.Get("protobuf")
195-
if m.EnumsAsString && !m.EnumsAsInts && strings.Contains(protoInfo, ",enum=") {
194+
if !m.EnumsAsInts && strings.Contains(protoInfo, ",enum=") {
196195
// Unknown enum values will are stringified by the proto library as their
197196
// value. Such values should _not_ be quoted or they will be interpreted
198197
// as an enum string instead of their value.

jsonpb/jsonpb_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ var (
4444
marshaler = Marshaler{}
4545

4646
marshalerAllOptions = Marshaler{
47-
EnumsAsString: true,
48-
Indent: " ",
47+
Indent: " ",
4948
}
5049

5150
simpleObject = &pb.Simple{
@@ -182,8 +181,8 @@ var (
182181
RRepeats: []*pb.Repeats{innerRepeats, innerRepeats2},
183182
}
184183

185-
complexObjectJSON = `{"color":1,` +
186-
`"r_color":[0,1,2],` +
184+
complexObjectJSON = `{"color":"GREEN",` +
185+
`"r_color":["RED","GREEN","BLUE"],` +
187186
`"simple":{"o_int32":-32},` +
188187
`"r_simple":[{"o_int32":-32},{"o_int64":"25"}],` +
189188
`"repeats":{"r_string":["roses","red"]},` +
@@ -269,7 +268,7 @@ var marshalingTests = []struct {
269268
{"repeated fields pretty object", marshalerAllOptions, repeatsObject, repeatsObjectPrettyJSON},
270269
{"nested message/enum flat object", marshaler, complexObject, complexObjectJSON},
271270
{"nested message/enum pretty object", marshalerAllOptions, complexObject, complexObjectPrettyJSON},
272-
{"enum-string flat object", Marshaler{EnumsAsString: true},
271+
{"enum-string flat object", Marshaler{},
273272
&pb.Widget{Color: pb.Widget_BLUE.Enum()}, `{"color":"BLUE"}`},
274273
{"enum-value pretty object", Marshaler{EnumsAsInts: true, Indent: " "},
275274
&pb.Widget{Color: pb.Widget_BLUE.Enum()}, colorPrettyJSON},

0 commit comments

Comments
 (0)