diff --git a/encoding/protojson/decode_test.go b/encoding/protojson/decode_test.go index faf5eb548..053d269b6 100644 --- a/encoding/protojson/decode_test.go +++ b/encoding/protojson/decode_test.go @@ -2203,7 +2203,9 @@ func TestUnmarshal(t *testing.T) { inputText: `{ "@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", inputMessage: &anypb.Any{}, diff --git a/encoding/protojson/well_known_types.go b/encoding/protojson/well_known_types.go index 4b177c820..e9fe10394 100644 --- a/encoding/protojson/well_known_types.go +++ b/encoding/protojson/well_known_types.go @@ -348,7 +348,11 @@ func (d decoder) unmarshalAnyValue(unmarshal unmarshalFunc, m protoreflect.Messa switch tok.Kind() { case json.ObjectClose: if !found { - return d.newError(tok.Pos(), `missing "value" field`) + // 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 nil