Issue with null

3 views
Skip to first unread message

iPhoneCode

unread,
Sep 4, 2009, 8:43:38 AM9/4/09
to ObjectiveResource
Hi folks,

I have realized something in Objective Support regarding the
deserialization of "null", at least JSON deserialization.
This test case {"test_class":{"created_at":null,"name":null}} results
in

TestClass.createdAt ==> nil
TestClass.name ==> "<null>"

Why does the library sets a JSON null as a NSString "<null>"?
Shouldn't it set as nil?

Rodrigo

Rodrigo Mazzilli

unread,
Sep 4, 2009, 8:53:41 AM9/4/09
to ObjectiveResource
I found the problem is in NSString+Deserialize.m:

+ (NSString *) deserialize:(id)value {
return [NSString stringWithFormat:@"%@",value];
}
If value is [NSNull null], we deserialize as (surprise!) "<null>". Is
this the expected behavior?

Rodrigo

Josh Vickery

unread,
Sep 4, 2009, 8:59:25 AM9/4/09
to objectiv...@googlegroups.com
Nice catch. If that's the problem, I think we could fix that with a
category on NSNull, NSNull+Deserialize that would have:

+ (NSString *) deserialize:(id)value {
return nil;
}

Care to give it a try and report back?

Josh

Rodrigo Mazzilli

unread,
Sep 4, 2009, 10:18:55 AM9/4/09
to ObjectiveResource
This approach doesn't work, as in NSObject+JSONSerializableSupport,
method deserializeJSON, we use the Class definition of the receiver,
i.e.
the objective_support class would need to have a NSNull * attribute,
which is obviously wrong.
The solution is very similar to the one we did in NSDate+Serialize.h.

I will fix it and push on my repository... details later.

Rodrigo

Rodrigo Mazzilli

unread,
Sep 4, 2009, 10:36:29 AM9/4/09
to ObjectiveResource
Fix is in on my github, master branch:
git://github.com/rodmaz/objectivesupport.git

This also includes a fix so we can use ObjectiveSupport with the
Three20 library.

Rodrigo

On Sep 4, 11:18 am, Rodrigo Mazzilli <rodrigo.mazzi...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages