@@ -379,9 +379,9 @@ var marshalingTests = []struct {
379
379
& pb.Mappy {Strry : map [string ]string {`"one"` : "two" , "three" : "four" }},
380
380
`{"strry":{"\"one\"":"two","three":"four"}}` },
381
381
{"map<int32, Object>" , marshaler ,
382
- & pb.Mappy {Objjy : map [int32 ]* pb.Simple3 {1 : & pb. Simple3 {Dub : 1 }}}, `{"objjy":{"1":{"dub":1}}}` },
382
+ & pb.Mappy {Objjy : map [int32 ]* pb.Simple3 {1 : {Dub : 1 }}}, `{"objjy":{"1":{"dub":1}}}` },
383
383
{"map<int32, Object>" , marshalerAllOptions ,
384
- & pb.Mappy {Objjy : map [int32 ]* pb.Simple3 {1 : & pb. Simple3 {Dub : 1 }}}, objjyPrettyJSON },
384
+ & pb.Mappy {Objjy : map [int32 ]* pb.Simple3 {1 : {Dub : 1 }}}, objjyPrettyJSON },
385
385
{"map<int64, string>" , marshaler , & pb.Mappy {Buggy : map [int64 ]string {1234 : "yup" }},
386
386
`{"buggy":{"1234":"yup"}}` },
387
387
{"map<bool, bool>" , marshaler , & pb.Mappy {Booly : map [bool ]bool {false : true }}, `{"booly":{"false":true}}` },
@@ -395,7 +395,7 @@ var marshalingTests = []struct {
395
395
{"proto2 map<int64, string>" , marshaler , & pb.Maps {MInt64Str : map [int64 ]string {213 : "cat" }},
396
396
`{"mInt64Str":{"213":"cat"}}` },
397
397
{"proto2 map<bool, Object>" , marshaler ,
398
- & pb.Maps {MBoolSimple : map [bool ]* pb.Simple {true : & pb. Simple {OInt32 : proto .Int32 (1 )}}},
398
+ & pb.Maps {MBoolSimple : map [bool ]* pb.Simple {true : {OInt32 : proto .Int32 (1 )}}},
399
399
`{"mBoolSimple":{"true":{"oInt32":1}}}` },
400
400
{"oneof, not set" , marshaler , & pb.MsgWithOneof {}, `{}` },
401
401
{"oneof, set" , marshaler , & pb.MsgWithOneof {Union : & pb.MsgWithOneof_Title {"Grand Poobah" }}, `{"title":"Grand Poobah"}` },
@@ -486,7 +486,7 @@ func TestMarshalAnyJSONPBMarshaler(t *testing.T) {
486
486
}
487
487
// after custom marshaling, it's round-tripped through JSON decoding/encoding already,
488
488
// so the keys are sorted, whitespace is compacted, and "@type" key has been added
489
- expected := `{"@type":"type.googleapis.com/` + dynamicMessageName + `","baz":[0,1,2,3],"foo":"bar"}`
489
+ expected := `{"@type":"type.googleapis.com/` + dynamicMessageName + `","baz":[0,1,2,3],"foo":"bar"}`
490
490
if str != expected {
491
491
t .Errorf ("marshalling JSON produced incorrect output: got %s, wanted %s" , str , expected )
492
492
}
@@ -535,7 +535,7 @@ var unmarshalingTests = []struct {
535
535
{"-Inf" , Unmarshaler {}, `{"oDouble":"-Infinity"}` , & pb.Simple {ODouble : proto .Float64 (math .Inf (- 1 ))}},
536
536
{"map<int64, int32>" , Unmarshaler {}, `{"nummy":{"1":2,"3":4}}` , & pb.Mappy {Nummy : map [int64 ]int32 {1 : 2 , 3 : 4 }}},
537
537
{"map<string, string>" , Unmarshaler {}, `{"strry":{"\"one\"":"two","three":"four"}}` , & pb.Mappy {Strry : map [string ]string {`"one"` : "two" , "three" : "four" }}},
538
- {"map<int32, Object>" , Unmarshaler {}, `{"objjy":{"1":{"dub":1}}}` , & pb.Mappy {Objjy : map [int32 ]* pb.Simple3 {1 : & pb. Simple3 {Dub : 1 }}}},
538
+ {"map<int32, Object>" , Unmarshaler {}, `{"objjy":{"1":{"dub":1}}}` , & pb.Mappy {Objjy : map [int32 ]* pb.Simple3 {1 : {Dub : 1 }}}},
539
539
{"proto2 extension" , Unmarshaler {}, realNumberJSON , realNumber },
540
540
{"Any with message" , Unmarshaler {}, anySimpleJSON , anySimple },
541
541
{"Any with message and indent" , Unmarshaler {}, anySimplePrettyJSON , anySimple },
@@ -645,6 +645,26 @@ func TestUnmarshaling(t *testing.T) {
645
645
}
646
646
}
647
647
648
+ func TestUnmarshalNullArray (t * testing.T ) {
649
+ var repeats pb.Repeats
650
+ if err := UnmarshalString (`{"rBool":null}` , & repeats ); err != nil {
651
+ t .Fatal (err )
652
+ }
653
+ if ! reflect .DeepEqual (repeats , pb.Repeats {}) {
654
+ t .Errorf ("got non-nil fields in [%#v]" , repeats )
655
+ }
656
+ }
657
+
658
+ func TestUnmarshalNullObject (t * testing.T ) {
659
+ var maps pb.Maps
660
+ if err := UnmarshalString (`{"mInt64Str":null}` , & maps ); err != nil {
661
+ t .Fatal (err )
662
+ }
663
+ if ! reflect .DeepEqual (maps , pb.Maps {}) {
664
+ t .Errorf ("got non-nil fields in [%#v]" , maps )
665
+ }
666
+ }
667
+
648
668
func TestUnmarshalNext (t * testing.T ) {
649
669
// We only need to check against a few, not all of them.
650
670
tests := unmarshalingTests [:5 ]
@@ -736,6 +756,7 @@ func TestUnmarshalAnyJSONPBUnmarshaler(t *testing.T) {
736
756
const (
737
757
dynamicMessageName = "google.protobuf.jsonpb.testing.dynamicMessage"
738
758
)
759
+
739
760
func init () {
740
761
// we register the custom type below so that we can use it in Any types
741
762
proto .RegisterType ((* dynamicMessage )(nil ), dynamicMessageName )
0 commit comments