diff --git a/request_test.go b/request_test.go index 300c7de..3dc0f66 100644 --- a/request_test.go +++ b/request_test.go @@ -784,7 +784,7 @@ func TestUnmarshalManyPayload(t *testing.T) { } in := bytes.NewReader(data) - posts, err := UnmarshalManyPayload(in, reflect.TypeOf(new(Post))) + posts, err := UnmarshalManyPayload[Post](in) if err != nil { t.Fatal(err) } @@ -792,13 +792,6 @@ func TestUnmarshalManyPayload(t *testing.T) { if len(posts) != 2 { t.Fatal("Wrong number of posts") } - - for _, p := range posts { - _, ok := p.(*Post) - if !ok { - t.Fatal("Was expecting a Post") - } - } } func TestManyPayload_withLinks(t *testing.T) { diff --git a/response.go b/response.go index b44e4e9..c2794bb 100644 --- a/response.go +++ b/response.go @@ -198,12 +198,19 @@ func visitModelNode(model interface{}, included *map[string]*Node, var er error value := reflect.ValueOf(model) - if value.IsNil() { + if value.Kind() == reflect.Ptr && value.IsNil() { return nil, nil } - modelValue := value.Elem() - modelType := value.Type().Elem() + var modelValue reflect.Value + var modelType reflect.Type + if value.Kind() == reflect.Ptr { + modelValue = value.Elem() + modelType = value.Type().Elem() + } else { + modelValue = value + modelType = value.Type() + } for i := 0; i < modelValue.NumField(); i++ { structField := modelValue.Type().Field(i)