Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot marshal JSON object to NSDictionary and vice versa #54

Closed
karaahmed opened this issue Mar 27, 2015 · 2 comments
Closed

Cannot marshal JSON object to NSDictionary and vice versa #54

karaahmed opened this issue Mar 27, 2015 · 2 comments

Comments

@karaahmed
Copy link

In Cordova one can call native APIs with JSON objects and they are converted to NSDictionary under the hood.
Consider the same behaviour for JSONArray <-> NSArray

@fealebenpae
Copy link
Contributor

Right now the bridge will convert an Array to an NSArray implicitly, but that's because I can recognize the Array exotic object. I can project the Map exotic object as NSDictionary the same way, but from what I gather Maps are not what you're after.

Type-coercing exotic objects is simple, but it becomes tricky to do correctly for plain JavaScript objects. I can't guess the purpose of an object - is it array-like, is it map-like, is it javascript-framework-du-jour's idea of a date, and so on. That's why there's no implicit conversion to NSDictionary today.

What I can do is convert an Object to a NSDictionary only when the target type is explicitly NSDictionary. That is to say, if a native function or method accepts CFDictionaryRef or NSDictionary. Would that work for you?

@fealebenpae
Copy link
Contributor

The runtime can now wrap JavaScript values in NSArray and NSDictionary instances:

  • When converting to id
    • Values of the JavaScript Array exotic object will be wrapped as NSArray
    • Values of the JavaScript Map exotic object will be wrapped as NSDictionary
  • When converting to NSArray or NSDictionary
    • Values of the JavaScript Array exotic object and plain JavaScript objects with a length property and indexed properties will be wrapped as NSArray
    • Values of the JavaScript Map exotic object and plain JavaScript objects will be wrapped as NSDictionary

Native NSArray and NSDictionary instances will still be exposed as Wrapper exotic objects to JavaScript, same as before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants