Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Crash when mapping JSON null to BOOL property
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  9 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Levi Brown  
View profile  
 More options Nov 13 2012, 11:38 am
From: Levi Brown <levigro...@gmail.com>
Date: Tue, 13 Nov 2012 08:38:15 -0800 (PST)
Local: Tues, Nov 13 2012 11:38 am
Subject: Crash when mapping JSON null to BOOL property

Hello all,

I've got some JSON coming back from a service which at some times will have
null instead of true/false for an attribute which is a boolean; Like this:

    "hide_locations" : null,

My object to receive this value has a property:

    @property (nonatomic, assign) BOOL hideLocations;

My mapping is configured like this:

    RKObjectMapping *retVal = [RKObjectMapping mappingForClass:[self class
]];

    [retVal mapKeyPath:@"hide_locations" toAttribute:@"hideLocations"];

But when I perform the mapping, RestKit 0.10.3 is crashing on this line:

    [self.destinationObject setValue:value forKeyPath:attributeMapping.
destinationKeyPath];
in
    - (void)applyAttributeMapping:(RKObjectAttributeMapping*)attributeMapping withValue:(
id)value

in RKObjectMappingOperation.m with the following error:

*2012-11-13 09:33:04.352 Tests[73816:5f03] *** Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason: '[<MyClass
0x13ba9a10> setNilValueForKey]: could not set nil as the value for the key
hideLocations.'*
*
*
It seems quite odd to me that a mature framework like this doesn't handle
this situation more gracefully, so I can't help but think I've configured
something incorrectly. I would appreciate any insights you might have.*
*

Thanks,

Levi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blake Watters  
View profile  
 More options Nov 13 2012, 7:47 pm
From: Blake Watters <bl...@gateguruapp.com>
Date: Tue, 13 Nov 2012 19:47:24 -0500
Local: Tues, Nov 13 2012 7:47 pm
Subject: Re: [RestKit] Crash when mapping JSON null to BOOL property

I would recommend trying this on the development branch. We have recently
merged type introspection support for non-object property types, which
should coerce the null into a false value. I will add a unit test for this
case to development to verify.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blake Watters  
View profile  
 More options Nov 13 2012, 8:43 pm
From: Blake Watters <bl...@gateguruapp.com>
Date: Tue, 13 Nov 2012 20:43:40 -0500
Local: Tues, Nov 13 2012 8:43 pm
Subject: Re: [RestKit] Crash when mapping JSON null to BOOL property

Actually the Boolean type introspection interprets the backing type as a
NSNumber. I have a failing test for this case and will think on how to
handle...

On Tue, Nov 13, 2012 at 7:47 PM, Blake Watters <bl...@gateguruapp.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Levi Brown  
View profile  
 More options Nov 14 2012, 11:39 am
From: Levi Brown <levigro...@gmail.com>
Date: Wed, 14 Nov 2012 08:39:39 -0800 (PST)
Local: Wed, Nov 14 2012 11:39 am
Subject: Re: [RestKit] Crash when mapping JSON null to BOOL property

Thanks Blake. I'll look forward to your solution.

Cheers,

Levi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blake Watters  
View profile  
 More options Nov 14 2012, 3:47 pm
From: Blake Watters <bl...@gateguruapp.com>
Date: Wed, 14 Nov 2012 15:47:13 -0500
Local: Wed, Nov 14 2012 3:47 pm
Subject: Re: [RestKit] Crash when mapping JSON null to BOOL property

You should probably just implement `setNilValueForKey:` on your target
object and handle it appropriately. I don't know that RK can or should try
to predict how you would want to handle a nil value for scalar types in all
cases, so its probably better to keep the behavior uniform. Such a
mapping will always invoke setNilValueForKey: where you can handle it as
appropriate for that model.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Levi Brown  
View profile  
 More options Nov 14 2012, 4:44 pm
From: Levi Brown <levigro...@gmail.com>
Date: Wed, 14 Nov 2012 13:44:39 -0800 (PST)
Local: Wed, Nov 14 2012 4:44 pm
Subject: Re: [RestKit] Crash when mapping JSON null to BOOL property

Blake,

Thanks for the suggestion and reply.

I respectfully disagree, however. To me it seems like RestKit should at
least gracefully handle this kind of situation, and not crash. For scalars
it seems pretty easy to have a set of default behaviors (that could be
augmented?)... for all numbers, null is zero. For Strings, null is null.
For booleans, null is false.

I think of this crash a bit like an SQL injection vulnerability. The
framework should protect against, and sanitize, malformed (intentionally or
not) input.

Levi


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blake Watters  
View profile  
 More options Dec 1 2012, 4:01 pm
From: Blake Watters <bl...@gateguruapp.com>
Date: Sat, 1 Dec 2012 16:01:20 -0500
Local: Sat, Dec 1 2012 4:01 pm
Subject: Re: [RestKit] Crash when mapping JSON null to BOOL property

Levi -

I appreciate the feedback. I have the tests laying around from investing
this in a work copy and I will reevaluate.

Cheers,
Blake


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Blake Watters  
View profile  
 More options Dec 26 2012, 2:47 pm
From: Blake Watters <bl...@gateguruapp.com>
Date: Wed, 26 Dec 2012 14:47:35 -0500
Local: Wed, Dec 26 2012 2:47 pm
Subject: Re: [RestKit] Crash when mapping JSON null to BOOL property

Hi Levi -

I have expanded the support for mapping to primitive types and we will now
coerce a null value into a numeric 0 value. Details are available on this
commit:
https://github.com/RestKit/RestKit/commit/b858f2753f5ec9d5c3f45b71151...

Will be included with pre5


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Levi Brown  
View profile  
 More options Dec 27 2012, 12:35 pm
From: Levi Brown <levigro...@gmail.com>
Date: Thu, 27 Dec 2012 09:35:12 -0800 (PST)
Local: Thurs, Dec 27 2012 12:35 pm
Subject: Re: [RestKit] Crash when mapping JSON null to BOOL property

Excellent. Thanks for taking the time and being responsive to feedback
Blake.

Happy Holidays!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »