java - How to avoid internal Nashorn classes in implementations of JSObject -


i want provide own implementation of jsobject described here: https://wiki.openjdk.java.net/display/nashorn/nashorn+extensions jsobject within jdk.nashorn.api package. unfortunately classes of objects in api-methods not. nativearray , jo4, both part of internal package. question is, how should handle such objects? recommended use internal functions? or possible cast objects in api-package?

here simple example:

import javax.script.invocable; import javax.script.scriptengine; import javax.script.scriptenginemanager; import javax.script.scriptexception; import jdk.nashorn.api.scripting.abstractjsobject;  public class jacksontojsobject extends abstractjsobject {      final static scriptengine engine = new scriptenginemanager().getenginebyname("nashorn");      public static void main(string[] args) throws scriptexception, nosuchmethodexception {         string script = "var fun = function(obj) {obj.arrayfield = [1,2]; obj.objfield = {\"field\":\"test\"}};";         engine.eval(script);         ((invocable)engine).invokefunction("fun", new jacksontojsobject());     }      @override     public void setmember(string name, object value) {         system.out.println(value.getclass().getcanonicalname());     }  } 

this output

jdk.nashorn.internal.objects.nativearray jdk.nashorn.internal.scripts.jo4 

i've filed bug against jdk https://bugs.openjdk.java.net/browse/jdk-8137258 automatically handle wrapping. in meanwhile, please use workaround suggested attila szegedi.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -