Skip to content

Commit

Permalink
Fix unmarshal null to existing value
Browse files Browse the repository at this point in the history
  • Loading branch information
neal committed Dec 19, 2024
1 parent 5e854fb commit 529b1f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
6 changes: 0 additions & 6 deletions gen/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 14 additions & 1 deletion tests/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 529b1f6

Please sign in to comment.