diff --git a/node.go b/node.go index a58488c..fe90df3 100644 --- a/node.go +++ b/node.go @@ -46,7 +46,7 @@ type Node struct { // RelationshipOneNode is used to represent a generic has one JSON API relation type RelationshipOneNode struct { - Data *Node `json:"data"` + Data *Node `json:"data,omitempty"` Links *Links `json:"links,omitempty"` Meta *Meta `json:"meta,omitempty"` } @@ -54,7 +54,7 @@ type RelationshipOneNode struct { // RelationshipManyNode is used to represent a generic has many JSON API // relation type RelationshipManyNode struct { - Data []*Node `json:"data"` + Data []*Node `json:"data,omitempty"` Links *Links `json:"links,omitempty"` Meta *Meta `json:"meta,omitempty"` } diff --git a/response_test.go b/response_test.go index 5b42595..2bf7e1e 100644 --- a/response_test.go +++ b/response_test.go @@ -116,43 +116,21 @@ func TestWithoutOmitsEmptyAnnotationOnRelation(t *testing.T) { } relationships := jsonData["data"].(map[string]interface{})["relationships"].(map[string]interface{}) - // Verifiy the "posts" relation was an empty array - posts, ok := relationships["posts"] + // Verify the "posts" relation was an empty array + _, ok := relationships["posts"] if !ok { t.Fatal("Was expecting the data.relationships.posts key/value to have been present") } - postsMap, ok := posts.(map[string]interface{}) - if !ok { - t.Fatal("data.relationships.posts was not a map") - } - postsData, ok := postsMap["data"] - if !ok { - t.Fatal("Was expecting the data.relationships.posts.data key/value to have been present") - } - postsDataSlice, ok := postsData.([]interface{}) - if !ok { - t.Fatal("data.relationships.posts.data was not a slice []") - } - if len(postsDataSlice) != 0 { - t.Fatal("Was expecting the data.relationships.posts.data value to have been an empty array []") - } - // Verifiy the "current_post" was a null + // Verify the "current_post" was a null currentPost, postExists := relationships["current_post"] if !postExists { t.Fatal("Was expecting the data.relationships.current_post key/value to have NOT been omitted") } - currentPostMap, ok := currentPost.(map[string]interface{}) + _, ok = currentPost.(map[string]interface{}) if !ok { t.Fatal("data.relationships.current_post was not a map") } - currentPostData, ok := currentPostMap["data"] - if !ok { - t.Fatal("Was expecting the data.relationships.current_post.data key/value to have been present") - } - if currentPostData != nil { - t.Fatal("Was expecting the data.relationships.current_post.data value to have been nil/null") - } } func TestWithOmitsEmptyAnnotationOnRelation(t *testing.T) {