jsonmodel / jsonmodel

Magical Data Modeling Framework for JSON - allows rapid creation of smart data models. You can use it in your iOS, macOS, watchOS and tvOS apps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BOOL are mapped to 1 and 0 instead of true and false

rurza opened this issue · comments

JSONModel 1.8.0

All BOOL properties are now mapped as a number instead of JS boolean. It can potentially break a lot of the existing code (like mine <3).

Unfortunately this is a pretty difficult problem - I believe there are a few property type encodings which are ambiguous. Probably relates to one of the recent PRs

I imagine relates to #569

If you can do a PR to fix, I’d be happy to get it pushed. Please make sure you include regression tests which fail with the current code and pass with your fix.

In our project, I've narrowed it down to e2c3421

This appears to be Mac OS-specific. I have a tiny reproducible case which passes when run under iOS tests, but fails under Mac OS tests.

// simple test object
@interface BoolTestObject : JSONModel
@property (nonatomic, assign) BOOL isAwesome;
@property (nonatomic, assign) BOOL isTerrible;
@end

@implementation BoolTestObject
@end

// https://github.com/jsonmodel/jsonmodel/issues/625
- (void) testBoolToJson {
	BoolTestObject *b = [[BoolTestObject alloc] init];
	b.isAwesome = YES;
	b.isTerrible = NO;

	NSString *expected = @"{\"isAwesome\":true,\"isTerrible\":false}";
	NSString *json = [b toJSONString];
	XCTAssertEqualObjects(expected, json); // fails on Mac OS
}
commented

I am having this problem on iOS versions <= iOS 10

Feel free to PR.