diff --git a/request.go b/request.go index 92cb2ec..b60968a 100644 --- a/request.go +++ b/request.go @@ -77,13 +77,17 @@ func unmarshalNode(data *Node, model reflect.Value, included *map[string]*Node) return false } - fieldValue := modelValue.Field(i) fieldType := modelType.Field(i) + tag := fieldType.Tag.Get("jsonapi") + if tag == "" { + i += 1 + return false + } + + fieldValue := modelValue.Field(i) i += 1 - tag := fieldType.Tag.Get("jsonapi") - args := strings.Split(tag, ",") if len(args) != 2 { diff --git a/response.go b/response.go index d00ba1e..9d42651 100644 --- a/response.go +++ b/response.go @@ -123,17 +123,21 @@ func visitModelNode(model interface{}, sideload bool) (*Node, []*Node, error) { var i = 0 modelType.FieldByNameFunc(func(name string) bool { - fieldValue := modelValue.Field(i) - structField := modelType.Field(i) - - i += 1 - - tag := structField.Tag.Get("jsonapi") - - if tag == "" { + if er != nil { return false } + structField := modelType.Field(i) + tag := structField.Tag.Get("jsonapi") + if tag == "" { + i += 1 + return false + } + + fieldValue := modelValue.Field(i) + + i += 1 + args := strings.Split(tag, ",") if len(args) != 2 { diff --git a/response_test.go b/response_test.go index f5c74f8..7ba5fa5 100644 --- a/response_test.go +++ b/response_test.go @@ -19,6 +19,7 @@ type Blog struct { } type Post struct { + Blog Id int `jsonapi:"primary,posts"` BlogId int `jsonapi:"attr,blog_id"` Title string `jsonapi:"attr,title"`