mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-30 21:32:43 +00:00
encoding/protojson: allow missing value for Any of type Empty
Some other implementations do not send the value field when encoding an Any representing a message of the Empty Well-Known-Type. Fixes golang/protobuf#1620 Change-Id: I89bffd5f92656ba3ac462c0b6365ed4b49e6189d Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/618395 Reviewed-by: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Stapelberg <stapelberg@google.com>
This commit is contained in:
parent
d34023800d
commit
fb995f184a
@ -2203,7 +2203,9 @@ func TestUnmarshal(t *testing.T) {
|
|||||||
inputText: `{
|
inputText: `{
|
||||||
"@type": "type.googleapis.com/google.protobuf.Empty"
|
"@type": "type.googleapis.com/google.protobuf.Empty"
|
||||||
}`,
|
}`,
|
||||||
wantErr: `(line 3:1): missing "value" field`,
|
wantMessage: &anypb.Any{
|
||||||
|
TypeUrl: "type.googleapis.com/google.protobuf.Empty",
|
||||||
|
},
|
||||||
}, {
|
}, {
|
||||||
desc: "Any with StringValue containing invalid UTF8",
|
desc: "Any with StringValue containing invalid UTF8",
|
||||||
inputMessage: &anypb.Any{},
|
inputMessage: &anypb.Any{},
|
||||||
|
@ -348,8 +348,12 @@ func (d decoder) unmarshalAnyValue(unmarshal unmarshalFunc, m protoreflect.Messa
|
|||||||
switch tok.Kind() {
|
switch tok.Kind() {
|
||||||
case json.ObjectClose:
|
case json.ObjectClose:
|
||||||
if !found {
|
if !found {
|
||||||
|
// We tolerate an omitted `value` field with the google.protobuf.Empty Well-Known-Type,
|
||||||
|
// for compatibility with other proto runtimes that have interpreted the spec differently.
|
||||||
|
if m.Descriptor().FullName() != genid.Empty_message_fullname {
|
||||||
return d.newError(tok.Pos(), `missing "value" field`)
|
return d.newError(tok.Pos(), `missing "value" field`)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case json.Name:
|
case json.Name:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user