I am serializing a custom class in Objective-C using JSONModel. The class User
that I am trying to serialize looks like:
<User>
[UserCount]: 658
[CreationDate]: 2014-04-17T00:38:34.176Z
[Credits]: 0
[Email]: Email Address
[Locale]: <nil>
[DeveloperDetails]: <nil>
[Name]: ashishagarwal
[UserName]: ashishagarwal
[_id]: xxxxxxxx--userid--------------
[FirstName]: First Name
[AuthenticationType]: <nil>
[_deleted]: 0
[LastActivityDate]: 2015-02-10T23:26:41.816Z
[Type]: 0
[IsAuthenticated]: 0
[LastName]: Last Name
[LastLoginDate]: 2015-02-12T03:39:50.626Z
</User>
There are a few nil
values, but that's expected.
I am trying to serialize using the line:
id json = [self.currentUser toJSONString];
The JSON, when printed out is:
{
"UserCount": 658,
"CreationDate": "2014-04-17T00:38:34.176Z",
"Credits": 0,
"Email": "Email Address",
"Name": "ashishagarwal",
"UserName": "ashishagarwal",
"_id": "xxxxxxxxxxxxxxxxxxxxxxxxxx",
"FirstName": "First Name",
"_deleted": false,
"LastActivityDate": "2015-02-10T23:26:41.816Z",
"Type": 0,
"IsAuthenticated": false,
"LastLoginDate": "2015-02-12T03:39:50.626Z",
"LastName": "Last Name"
}
The values that were nil
have disappeared. Is there a way to have them marked as "null" when serializing ?