Skip to content

Commit 5dd9b1b

Browse files
mzkiparalin
authored andcommitted
fix(json): unmarshal non-null empty message properly
1 parent 60d0e2b commit 5dd9b1b

File tree

4 files changed

+445
-1
lines changed

4 files changed

+445
-1
lines changed

features/json/message-unmarshal.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ func (g *jsonGenerator) genMessageUnmarshaler(message *protogen.Message) {
2121
g.P("}")
2222

2323
// If the message doesn't have any fields, there's nothing to do.
24+
// But need to consume empty object braces like "{}".
2425
if len(message.Fields) == 0 {
25-
g.P("}") // end func (x *{message.GoIdent}) MarshalProtoJSON()
26+
g.P("s.ReadObject(func(key string) {")
27+
g.P("// no fields")
28+
g.P("})") // end s.ReadObject()
29+
g.P("}") // end func (x *{message.GoIdent}) MarshalProtoJSON()
2630
g.P()
2731
return
2832
}

0 commit comments

Comments
 (0)