diff --git a/roller.go b/roller.go index 11e4a58..45431e2 100644 --- a/roller.go +++ b/roller.go @@ -183,6 +183,10 @@ func (r *roller) traverseMap(iface interface{}) { switch t := iface.(type) { case map[string]interface{}: for k, v := range t { + // drop null values in json to prevent panic caused by reflect.TypeOf(nil) + if v == nil { + continue + } switch reflect.TypeOf(v).Kind() { case reflect.Struct: r.typeName = k // set the map key as name diff --git a/roller_test.go b/roller_test.go index 30e2032..e6a46b7 100644 --- a/roller_test.go +++ b/roller_test.go @@ -83,6 +83,7 @@ func init() { m["person"] = "John Doe" m["iface"] = map[string]string{"another_person": "does it change root!"} m["array"] = [5]int{1, 4, 5, 6, 7} + m["null"] = nil } func TestRoller_push(t *testing.T) {