jamztang/JTObjectMapping

Crash if there is a property called "description"

rnaud opened this issue · 5 comments

If in the JSON one of the key is called description the whole this crahes. :)

I haven't had a chance to look at the crash, but I'd suggest not using "description" for an Obj-C Property name. It's already a special method defined to be the string representation of your instance. (If you don't control the JSON, you can map it to another property name.)

On Sep 3, 2012, at 6:11 AM, Arnaud Ferreri notifications@github.com wrote:

If in the JSON one of the key is called description the whole this crahes. :)


Reply to this email directly or view it on GitHub.

Hey, I was actually mapping it to another property. I'm not even sure you can declare a property named "description".
So I was mapping the "description" json attribute to a "desc" property on the object but the crash happens on the enumeration of the NSDictionnary keys. Or so I've seen.

Other than that the lib is incredible, saving me tons of time!

Interesting, thanks. I'll take a look when I get a chance.

On Sep 3, 2012, at 11:47 AM, Arnaud Ferreri notifications@github.com wrote:

Hey, I was actually mapping it to another property. I'm not even sure you can declare a property named "description".
So I was mapping the "description" json attribute to a "desc" property on the object but the crash happens on the enumeration of the NSDictionnary keys. Or so I've seen.

Other than that the lib is incredible, saving me tons of time!


Reply to this email directly or view it on GitHub.

I see your problem here. Just stumbled upon the same. Issue to me seems to be on the enumeration code. Why is it walking from the JSON object (dict or array) and looking for a map key, instead of going the other way? I see 2 problems with this approach:
1 - If you construct your object with a subset of it, it goes through every key anyway and if failed goes for a key-path search. A performance concern.
2 - It may alter properties that you were not trying to set from the JSON. This might be serious.
Hope I helped here, I'd like to see this working.. as I am not a big fan of RestKit really.
Thanks.

Hi @rnaud, @zcharter,

Thanks, I've change the auto mapping logic so that it won't map if there's no setter method for that key. Although you can now, you should still prevent using preserved keyword for your JSON response if possible.

Hi @hernangonzalez,

Thanks for your concern. I am imagining that going either way has to enumerate the properties, do you have any case studies so that we can picture that up? Maybe we can talk about that in another thread, please feel free to open an issue for this.