handle pointers being dumb

This commit is contained in:
Preston Baxter 2023-11-21 19:14:36 -06:00
parent b73a8a772f
commit 403bd2e40b
2 changed files with 11 additions and 11 deletions

View File

@ -784,7 +784,7 @@ func TestUnmarshalManyPayload(t *testing.T) {
} }
in := bytes.NewReader(data) in := bytes.NewReader(data)
posts, err := UnmarshalManyPayload(in, reflect.TypeOf(new(Post))) posts, err := UnmarshalManyPayload[Post](in)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -792,13 +792,6 @@ func TestUnmarshalManyPayload(t *testing.T) {
if len(posts) != 2 { if len(posts) != 2 {
t.Fatal("Wrong number of posts") 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) { func TestManyPayload_withLinks(t *testing.T) {

View File

@ -198,12 +198,19 @@ func visitModelNode(model interface{}, included *map[string]*Node,
var er error var er error
value := reflect.ValueOf(model) value := reflect.ValueOf(model)
if value.IsNil() { if value.Kind() == reflect.Ptr && value.IsNil() {
return nil, nil return nil, nil
} }
modelValue := value.Elem() var modelValue reflect.Value
modelType := value.Type().Elem() 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++ { for i := 0; i < modelValue.NumField(); i++ {
structField := modelValue.Type().Field(i) structField := modelValue.Type().Field(i)