Atilla,
Yes, FreeMarker is a perfect example of how I'd love to see this work.
Where do you imagine this could fit in to the Rhino roadmap?

Patrick

On Wed, Mar 4, 2009 at 6:25 AM, Attila Szegedi <[email protected]> wrote:
> Honestly, there should be advanced type coercion. We're sticking to the
> LiveConnect "standard" for Java-JS interop, but my own opinion is that
> LiveConnect is outdated and we should enhance it any way we see fit
> (starting with recognizing boolean as a first-class data type!).
> Automatically coercing a Scriptable to Map sounds like one of these things
> that should Just Work(TM). I certainly implemented all kinds of
> commonsensical coercions to expected Java types over in the FreeMarker
> project, and people are generally happy when their language runtimes do that
> work for them...
>
> Attila.
>
> On 2009.03.04., at 15:20, Patrick Lightbody wrote:
>
>> Ruland,
>> OK - that's what I ended up doing last night. I was just hoping there
>> would be some sort of more advanced type coercion system. No biggie -
>> thanks!
>>
>> Patrick
>>
>> On Wed, Mar 4, 2009 at 4:12 AM, Ruland Kevin-BHP637
>> <[email protected]> wrote:
>>>
>>> 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

Reply via email to