From 37828f962262b5a0f3d9560c429a14d96c711a21 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Wed, 15 Sep 2021 16:28:59 -0700 Subject: [PATCH] jsonpb: accept 'null' as a valid representation of NullValue in unmarshal The canonical JSON representation for NullValue is JSON "null". Fixes github.com/golang/protobuf#1361. --- internal/testprotos/jsonpb_proto/test2.pb.go | 209 ++++++++++--------- internal/testprotos/jsonpb_proto/test2.proto | 1 + jsonpb/decode.go | 8 +- jsonpb/json_test.go | 2 + 4 files changed, 123 insertions(+), 97 deletions(-) diff --git a/internal/testprotos/jsonpb_proto/test2.pb.go b/internal/testprotos/jsonpb_proto/test2.pb.go index a27dc0c256..1dc0f8a03b 100644 --- a/internal/testprotos/jsonpb_proto/test2.pb.go +++ b/internal/testprotos/jsonpb_proto/test2.pb.go @@ -586,6 +586,7 @@ type MsgWithOneof struct { // *MsgWithOneof_Country // *MsgWithOneof_HomeAddress // *MsgWithOneof_MsgWithRequired + // *MsgWithOneof_NullValue Union isMsgWithOneof_Union `protobuf_oneof:"union"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -641,6 +642,10 @@ type MsgWithOneof_MsgWithRequired struct { MsgWithRequired *MsgWithRequired `protobuf:"bytes,5,opt,name=msg_with_required,json=msgWithRequired,oneof"` } +type MsgWithOneof_NullValue struct { + NullValue structpb.NullValue `protobuf:"varint,6,opt,name=null_value,json=nullValue,enum=google.protobuf.NullValue,oneof"` +} + func (*MsgWithOneof_Title) isMsgWithOneof_Union() {} func (*MsgWithOneof_Salary) isMsgWithOneof_Union() {} @@ -651,6 +656,8 @@ func (*MsgWithOneof_HomeAddress) isMsgWithOneof_Union() {} func (*MsgWithOneof_MsgWithRequired) isMsgWithOneof_Union() {} +func (*MsgWithOneof_NullValue) isMsgWithOneof_Union() {} + func (m *MsgWithOneof) GetUnion() isMsgWithOneof_Union { if m != nil { return m.Union @@ -693,6 +700,13 @@ func (m *MsgWithOneof) GetMsgWithRequired() *MsgWithRequired { return nil } +func (m *MsgWithOneof) GetNullValue() structpb.NullValue { + if x, ok := m.GetUnion().(*MsgWithOneof_NullValue); ok { + return x.NullValue + } + return structpb.NullValue_NULL_VALUE +} + // XXX_OneofWrappers is for the internal use of the proto package. func (*MsgWithOneof) XXX_OneofWrappers() []interface{} { return []interface{}{ @@ -701,6 +715,7 @@ func (*MsgWithOneof) XXX_OneofWrappers() []interface{} { (*MsgWithOneof_Country)(nil), (*MsgWithOneof_HomeAddress)(nil), (*MsgWithOneof_MsgWithRequired)(nil), + (*MsgWithOneof_NullValue)(nil), } } @@ -1177,100 +1192,102 @@ func init() { func init() { proto.RegisterFile("jsonpb_proto/test2.proto", fileDescriptor_50cab1d8463dea41) } var fileDescriptor_50cab1d8463dea41 = []byte{ - // 1510 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x57, 0xdd, 0x6e, 0xdb, 0x46, - 0x16, 0x36, 0x49, 0x51, 0x12, 0x8f, 0x6c, 0xc7, 0x1e, 0x3b, 0x09, 0xed, 0x0d, 0xb2, 0x84, 0xb2, - 0xd9, 0xd5, 0x26, 0x58, 0x79, 0x43, 0x0b, 0x42, 0x91, 0x36, 0x40, 0xe3, 0xd8, 0x6e, 0xd2, 0x24, - 0x4e, 0x41, 0x27, 0x0d, 0xda, 0x1b, 0x81, 0x32, 0x29, 0x99, 0x2d, 0xc9, 0x51, 0x67, 0x46, 0x4e, - 0x84, 0xb6, 0x80, 0xfb, 0x0a, 0x7d, 0x85, 0x02, 0xbd, 0xed, 0x5d, 0x2f, 0xfa, 0x1c, 0x45, 0x9f, - 0xa7, 0x98, 0x33, 0x43, 0xfd, 0x59, 0x36, 0x72, 0x65, 0xcd, 0x7c, 0x3f, 0x33, 0x9c, 0xf3, 0xf1, - 0x0c, 0x0d, 0xee, 0x37, 0x9c, 0xe6, 0x83, 0x6e, 0x67, 0xc0, 0xa8, 0xa0, 0x3b, 0x22, 0xe6, 0xc2, - 0x6f, 0xe2, 0x6f, 0x52, 0xd3, 0x88, 0x9c, 0xdb, 0xde, 0xea, 0x53, 0xda, 0x4f, 0xe3, 0x1d, 0x84, - 0xba, 0xc3, 0xde, 0x4e, 0x98, 0x8f, 0x14, 0x6f, 0xfb, 0xf6, 0x3c, 0x14, 0x0d, 0x59, 0x28, 0x12, - 0x9a, 0x6b, 0xfc, 0xd6, 0x3c, 0xce, 0x05, 0x1b, 0x9e, 0x08, 0x8d, 0xfe, 0x73, 0x1e, 0x15, 0x49, - 0x16, 0x73, 0x11, 0x66, 0x83, 0xcb, 0xec, 0xdf, 0xb1, 0x70, 0x30, 0x88, 0x19, 0x57, 0x78, 0xfd, - 0xb7, 0x12, 0x94, 0x8f, 0x93, 0x6c, 0x90, 0xc6, 0xe4, 0x3a, 0x94, 0x69, 0xa7, 0x4b, 0x69, 0xea, - 0x1a, 0x9e, 0xd1, 0xa8, 0x06, 0x36, 0xdd, 0xa3, 0x34, 0x25, 0x37, 0xa1, 0x42, 0x3b, 0x49, 0x2e, - 0x76, 0x7d, 0xd7, 0xf4, 0x8c, 0x86, 0x1d, 0x94, 0xe9, 0x33, 0x39, 0x22, 0xb7, 0xa1, 0xa6, 0x81, - 0x0e, 0x17, 0xcc, 0xb5, 0x10, 0x74, 0x14, 0x78, 0x2c, 0xd8, 0x58, 0xd8, 0x6e, 0xb9, 0x25, 0xcf, - 0x68, 0x58, 0x4a, 0xd8, 0x6e, 0x8d, 0x85, 0xed, 0x16, 0x0a, 0x6d, 0x04, 0x1d, 0x05, 0x4a, 0xe1, - 0x16, 0x54, 0x69, 0x67, 0xa8, 0x96, 0x2c, 0x7b, 0x46, 0x63, 0x25, 0xa8, 0xd0, 0x37, 0x38, 0x24, - 0x1e, 0x2c, 0x17, 0x10, 0x6a, 0x2b, 0x08, 0x83, 0x86, 0x67, 0xc4, 0xed, 0x96, 0x5b, 0xf5, 0x8c, - 0x46, 0x49, 0x8b, 0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4f, 0xb7, 0x65, 0x47, 0xb5, 0x65, 0x7f, - 0xb6, 0x2d, 0x5f, 0xed, 0x3d, 0xd5, 0x9f, 0xef, 0xc1, 0xe6, 0x1c, 0x8a, 0x15, 0x20, 0x04, 0x4a, - 0xdd, 0x91, 0xe0, 0x78, 0xc6, 0xcb, 0x01, 0xfe, 0xae, 0xef, 0x03, 0x99, 0xe3, 0xbe, 0x7d, 0xfe, - 0xba, 0x88, 0x80, 0x24, 0x7e, 0x48, 0x04, 0x1e, 0xde, 0x85, 0x52, 0x1e, 0x66, 0xf1, 0xa2, 0x96, - 0xf6, 0x03, 0x3e, 0x0f, 0xc2, 0x0f, 0x9f, 0x40, 0x29, 0x7e, 0x2f, 0xb2, 0x45, 0xb4, 0x1f, 0x3f, - 0xa4, 0x90, 0x52, 0xbc, 0xf7, 0xe8, 0xeb, 0x8f, 0xfb, 0x89, 0x38, 0x1d, 0x76, 0x9b, 0x27, 0x34, - 0xdb, 0xe9, 0xd3, 0x34, 0xcc, 0xfb, 0x93, 0xff, 0x8b, 0x92, 0x5c, 0xc4, 0x2c, 0x0f, 0x53, 0xfc, - 0x27, 0x0e, 0x67, 0xf9, 0xce, 0xf4, 0x3f, 0x77, 0x7f, 0x07, 0x00, 0x00, 0xff, 0xff, 0xba, 0x6b, - 0x0b, 0xa0, 0xeb, 0x0d, 0x00, 0x00, + // 1537 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x57, 0xdd, 0x6e, 0xdb, 0xc8, + 0x15, 0x36, 0x49, 0x51, 0x12, 0x8f, 0xec, 0xc4, 0x99, 0x64, 0x37, 0xb4, 0x1b, 0x6c, 0x09, 0x6d, + 0xb7, 0x55, 0xb3, 0xa8, 0xdc, 0xa5, 0x05, 0xa1, 0xc8, 0x76, 0x81, 0xae, 0x13, 0xa7, 0xd9, 0xee, + 0xc6, 0x5b, 0x8c, 0x93, 0x06, 0xed,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, 0x97, 0xff, 0x54, 0xe5, 0x4c, 0x65, 0x82, 0x25, 0x05, 0xfe, 0x07, 0x88, 0xb3, 0xf2, 0x68, + 0xf5, 0x3f, 0xc3, 0xef, 0x02, 0x00, 0x00, 0xff, 0xff, 0x5b, 0xac, 0xa6, 0xa5, 0x28, 0x0e, 0x00, + 0x00, } diff --git a/internal/testprotos/jsonpb_proto/test2.proto b/internal/testprotos/jsonpb_proto/test2.proto index d34dc33d6b..f41c0ec486 100644 --- a/internal/testprotos/jsonpb_proto/test2.proto +++ b/internal/testprotos/jsonpb_proto/test2.proto @@ -91,6 +91,7 @@ message MsgWithOneof { string Country = 3; string home_address = 4; MsgWithRequired msg_with_required = 5; + google.protobuf.NullValue null_value = 6; } } diff --git a/jsonpb/decode.go b/jsonpb/decode.go index 60e82caa9a..6c16c255ff 100644 --- a/jsonpb/decode.go +++ b/jsonpb/decode.go @@ -386,8 +386,14 @@ func (u *Unmarshaler) unmarshalMessage(m protoreflect.Message, in []byte) error } func isSingularWellKnownValue(fd protoreflect.FieldDescriptor) bool { + if fd.Cardinality() == protoreflect.Repeated { + return false + } if md := fd.Message(); md != nil { - return md.FullName() == "google.protobuf.Value" && fd.Cardinality() != protoreflect.Repeated + return md.FullName() == "google.protobuf.Value" + } + if ed := fd.Enum(); ed != nil { + return ed.FullName() == "google.protobuf.NullValue" } return false } diff --git a/jsonpb/json_test.go b/jsonpb/json_test.go index a98ad169f2..39427734ec 100644 --- a/jsonpb/json_test.go +++ b/jsonpb/json_test.go @@ -441,6 +441,7 @@ var marshalingTests = []struct { `{"mBoolSimple":{"true":{"oInt32":1}}}`}, {"oneof, not set", marshaler, &pb2.MsgWithOneof{}, `{}`}, {"oneof, set", marshaler, &pb2.MsgWithOneof{Union: &pb2.MsgWithOneof_Title{"Grand Poobah"}}, `{"title":"Grand Poobah"}`}, + {"oneof NullValue", marshaler, &pb2.MsgWithOneof{Union: &pb2.MsgWithOneof_NullValue{stpb.NullValue_NULL_VALUE}}, `{"nullValue":null}`}, {"force orig_name", Marshaler{OrigName: true}, &pb2.Simple{OInt32: proto.Int32(4)}, `{"o_int32":4}`}, {"proto2 extension", marshaler, realNumber, realNumberJSON}, @@ -738,6 +739,7 @@ var unmarshalingTests = []struct { {"oneof orig_name", Unmarshaler{}, `{"Country":"Australia"}`, &pb2.MsgWithOneof{Union: &pb2.MsgWithOneof_Country{"Australia"}}}, {"oneof spec name2", Unmarshaler{}, `{"homeAddress":"Australia"}`, &pb2.MsgWithOneof{Union: &pb2.MsgWithOneof_HomeAddress{"Australia"}}}, {"oneof orig_name2", Unmarshaler{}, `{"home_address":"Australia"}`, &pb2.MsgWithOneof{Union: &pb2.MsgWithOneof_HomeAddress{"Australia"}}}, + {"oneof NullValue", Unmarshaler{}, `{"nullValue":null}`, &pb2.MsgWithOneof{Union: &pb2.MsgWithOneof_NullValue{stpb.NullValue_NULL_VALUE}}}, {"orig_name input", Unmarshaler{}, `{"o_bool":true}`, &pb2.Simple{OBool: proto.Bool(true)}}, {"camelName input", Unmarshaler{}, `{"oBool":true}`, &pb2.Simple{OBool: proto.Bool(true)}},