How to map the json key in CBLDocument to different name in the CBLModel subclass?

28 views
Skip to first unread message

Ahmed

unread,
Sep 4, 2015, 8:29:21 PM9/4/15
to Couchbase Mobile
Hi,

I've a CBLDocument contains object like this { "user-name": "abc" }, the problem is that when i try to make CBLModel it is not allowed name a property with dashes, is there is any way to map the json key to different name in the CBLModel subclass?

Thanks

Jens Alfke

unread,
Sep 4, 2015, 9:33:10 PM9/4/15
to mobile-c...@googlegroups.com

On Sep 4, 2015, at 4:54 PM, Ahmed <eng.ahmed...@gmail.com> wrote:

I've a CBLDocument contains object like this { "user-name": "abc" }, the problem is that when i try to make CBLModel it is not allowed name a property with dashes, is there is any way to map the json key to different name in the CBLModel subclass?

No, sorry. I think it’s been requested before, though, so there’s probably an issue for it in the Github repo.

The workaround is to use [self getValueOfProperty: @“user-name”] and [self setValue: name ofProperty: @“user-name”]. You can wrap those in -userName and -setUserName: method if you like, to make it into a real Obj-C property.

—Jens
Reply all
Reply to author
Forward
0 new messages