From 529b1f6f7ec18fbae380d7ce72d38061e5201498 Mon Sep 17 00:00:00 2001 From: Neal Patel Date: Wed, 18 Dec 2024 21:43:31 -0800 Subject: [PATCH] Fix unmarshal null to existing value --- gen/decoder.go | 6 ------ tests/basic_test.go | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gen/decoder.go b/gen/decoder.go index 0a0faa26..df1a4bd3 100644 --- a/gen/decoder.go +++ b/gen/decoder.go @@ -320,7 +320,6 @@ func (g *Generator) genTypeDecoderNoCheck(t reflect.Type, out string, tags field return fmt.Errorf("don't know how to decode %v", t) } return nil - } func (g *Generator) interfaceIsEasyjsonUnmarshaller(t reflect.Type) bool { @@ -514,11 +513,6 @@ func (g *Generator) genStructDecoder(t reflect.Type) error { fmt.Fprintln(g.out, " for !in.IsDelim('}') {") fmt.Fprintf(g.out, " key := in.UnsafeFieldName(%v)\n", g.skipMemberNameUnescaping) fmt.Fprintln(g.out, " in.WantColon()") - fmt.Fprintln(g.out, " if in.IsNull() {") - fmt.Fprintln(g.out, " in.Skip()") - fmt.Fprintln(g.out, " in.WantComma()") - fmt.Fprintln(g.out, " continue") - fmt.Fprintln(g.out, " }") fmt.Fprintln(g.out, " switch key {") for _, f := range fs { diff --git a/tests/basic_test.go b/tests/basic_test.go index e18e515c..190f6d01 100644 --- a/tests/basic_test.go +++ b/tests/basic_test.go @@ -205,7 +205,6 @@ func TestEncodingFlags(t *testing.T) { t.Errorf("[%v] easyjson.Marshal(%+v) = %v; want %v", i, test.In, v, test.Want) } } - } func TestNestedEasyJsonMarshal(t *testing.T) { @@ -329,3 +328,17 @@ func TestNil(t *testing.T) { t.Errorf("Wanted null, got %q", s) } } + +func TestUnmarshalNull(t *testing.T) { + p := primitiveTypesValue + + data := `{"Ptr":null}` + + if err := easyjson.Unmarshal([]byte(data), &p); err != nil { + t.Errorf("easyjson.Unmarshal() error: %v", err) + } + + if p.Ptr != nil { + t.Errorf("Wanted nil, got %q", *p.Ptr) + } +}