mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
Merge pull request #407 from Neal/bugfix/unmarshal-null
Fix unmarshal null to existing value
This commit is contained in:
@@ -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
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user