I am having a problem with null JSON values being mapped to objects in Core Data, which causes errors. An example of a GET response from my server is:
{
"status": "Success",
"result": {
"users": [
{
"id": 240,
"username": "user",
"fullName": "My Name",
"profilePicture": {
"id": 12,
"ownerID": "240",
"imageURL": "/photos/240/12",
}
},
{
"id": 241,
"username": "username",
"fullName": "Full Name",
"profilePicture": NULL
}
]
}
}
I have set up RestKit 0.22.0 to map the JSON value for "profilePicture" as a relationship (of entity type Photo
) for the User
entity. The relationship profilePicture
is optional for User
entities. The problem occurs when the database returns a NULL value (AKA the user has not set a profile picture). RestKit will create a new Photo
entity with all properties equal to nil and set it to the profilePicture
relationship of the User
entity. This causes many problems for me. How can I prevent NULL values from being mapped?
I have tried setting userMapping.assignsNilForMissingRelationships = YES
, but this doesn't seem to work.
EDIT: I should point out that everything works great when the user has set their profile picture. I only get problems when the returned profilePicture value is NULL.
UPDATE: Even after changing the API to omit the "profilePicture" key/value pair altogether when NULL, RestKit still assigns the User
entity's profilePicture
relationship to a Photo
entity with all nil
attributes.