forked from Mirrors/jsonapi
handle pointers being dumb
This commit is contained in:
parent
b73a8a772f
commit
403bd2e40b
|
@ -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) {
|
||||
|
|
13
response.go
13
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)
|
||||
|
|
Loading…
Reference in New Issue