closes #9: Fixed parsing null as a struct.

This commit is contained in:
Victor Starodub
2016-04-13 16:17:22 +03:00
parent 92fdbb21de
commit 019100ee69
2 changed files with 15 additions and 0 deletions
+4
View File
@@ -214,6 +214,10 @@ func (g *Generator) genStructDecoder(t reflect.Type) error {
typ := g.getType(t)
fmt.Fprintln(g.out, "func "+fname+"(in *jlexer.Lexer, out *"+typ+") {")
fmt.Fprintln(g.out, " if in.IsNull() {")
fmt.Fprintln(g.out, " in.Skip()")
fmt.Fprintln(g.out, " return")
fmt.Fprintln(g.out, " }")
// Init embedded pointer fields.
for i := 0; i < t.NumField(); i++ {
+11
View File
@@ -91,3 +91,14 @@ func TestRawMessageSTD(t *testing.T) {
t.Errorf("json.Unmarshal() = %v; want %v", gotV, wantV)
}
}
func TestParseNull(t *testing.T) {
var got, want SubStruct
if err := easyjson.Unmarshal([]byte("null"), &got); err != nil {
t.Errorf("Unmarshal() error: %v", err)
}
if !reflect.DeepEqual(got, want) {
t.Errorf("Unmarshal() = %+v; want %+v", got, want)
}
}