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
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
foo.someJavaMethod({
key: 'value'
});
Where someJavaMethod looks like:
Patrick
_______________________________________________
dev-tech-js-engine-rhino mailing list
dev-tech-js-...@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
Patrick
Attila.
Marcello