Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RESTKit object BOOL property to true/false JSON

I have some objects which I'm sending to a server as JSON, in the request body, for a POST request. My question relates to boolean properties.

Say I have this property in an object I'm sending as JSON:

@property (nonatomic) BOOL exported;

By default, RestKit sends the boolean as either 1 or 0 in JSON. How can I setup RestKit so that all BOOLs are sent as true or false (which is the JSON boolean type).

Funnily enough, when going the other way, from JSON true or false to the BOOL property, RestKit reads the JSON true/false just fine, appropriately setting the property.

like image 886
Diego Barros Avatar asked Jul 26 '13 06:07

Diego Barros


2 Answers

Alternatively; you could make it a bool instead of a BOOL and restkit will parse it properly.

@property (nonatomic) bool exported;

The reason it handles it properly in a read is that bool's are inherently just 1 or 0... so Restkit is smart enough to convert it to a BOOL.

like image 98
ender44 Avatar answered Jan 03 '23 12:01

ender44


Source type :NSCFBoolean 
Destination type : NSString
Discussion: Boolean literals true and false parsed from JSON are mapped to NSString properties as @"true" and @"false"

Source :See This table

like image 39
Lithu T.V Avatar answered Jan 03 '23 12:01

Lithu T.V