Merge pull request #407 from Neal/bugfix/unmarshal-null

Fix unmarshal null to existing value
This commit is contained in:
Vasily Romanov
2024-12-21 18:08:13 +03:00
committed by GitHub
2 changed files with 14 additions and 7 deletions
-6
View File
@@ -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 {
+14 -1
View File
@@ -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)
}
}