Effective way to pass JSON between java and javascript

江枫思渺然 提交于 2019-12-03 07:13:01

Nashorn treats java.util.Map objects specially. Nashorn allows Map keys to be treated as "properties". See also https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions#Nashornextensions-SpecialtreatmentofobjectsofspecificJavaclasses

So if your map contains "foo" as key, script can access mapObj.foo to get it's value. It does not matter the script you evaluated is third-party one. As long as the script is evaluated by Nashorn, nashorn will specially link Map property access and get the result you want. This approach avoid unnecessary JSON string conversion and parse round trip (as you yourself mentioned).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!