Patrick,
I'm typing this off the cuff, it might not be fully correct.
NativeObject.getIds() returns all the property names. This includes
array indexes. This snippet of code should properly decode arrays (or
array portions of objects) into the map. The keys to the array values
are the string representation of the index number.
public Map<String,Object> objectToMap( NativeObject obj ) {
HashMap<String,Object> map = new HashMap<String,Object>();
for( Object id: obj.getIds() ) {
String key;
Object value;
if (id instanceof String ) {
key = (String) id;
value = obj.get(key,obj);
} else if (id instanceof Integer) {
key = id.toString();
value = obj.get( ((Integer)id).intValue(), obj);
} else {
throw new IllegalArgumentException();
}
map.put( key, value );
}
return map;
}
Kevin
-----Original Message-----
From:
dev-tech-js-engine-rhino-bounces+kruland=motorola....@lists.mozilla.org
[mailto:[email protected]
lla.org] On Behalf Of Patrick Lightbody
Sent: Tuesday, March 03, 2009 11:33 PM
To: [email protected]
Subject: Converting JS to Map
I'd like to have my JS code do something like this:
foo.someJavaMethod({
key: 'value'
});
Where someJavaMethod looks like:
public void someJavaMethod(Map<String, String> params) {
...
}
However, when I do that, I get an error in JS: "Cannot convert [object
Object] to java.util.Map". If I make params an Object, then I can get
a handle to the NativeObject, but I can't quite figure out how to
navigate and convert it through. Any tips?
Patrick
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino