Skip to content

Commit 75c1ea6

Browse files
committed
Add support for empty to-one relationship according to JSON API v1.0 specification
1 parent d8790c3 commit 75c1ea6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Classes/JSONAPIResourceParser.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,20 @@ + (void)set:(NSObject <JSONAPIResource> *)resource withDictionary:dictionary {
200200
if (property.resourceType) {
201201
if (relationships) {
202202
id value = [relationships objectForKey:[property jsonName]];
203-
[resource setValue:[JSONAPIResourceParser jsonAPILink:value] forKey:key];
203+
if (value[@"data"] != [NSNull null]) {
204+
[resource setValue:[JSONAPIResourceParser jsonAPILink:value] forKey:key];
205+
}
204206
}
205207

206208
} else if (relationships[key]) {
207209
if (relationships) {
208210
id value = relationships[key];
209-
[resource setValue:[JSONAPIResourceParser jsonAPILink:value] forKey:key];
211+
if (value[@"data"] != [NSNull null]) {
212+
[resource setValue:[JSONAPIResourceParser jsonAPILink:value] forKey:key];
213+
}
210214
}
211215
} else {
212-
id value = [attributes objectForKey:[property jsonName]];;
216+
id value = [attributes objectForKey:[property jsonName]];
213217
if ((id)[NSNull null] == value) {
214218
value = [dictionary objectForKey:[property jsonName]];
215219
}

0 commit comments

Comments
 (0)