Effective way to pass JSON between java and javascript

后端 未结 1 1278
刺人心
刺人心 2021-02-06 09:01

I\'m fairly new to Nashorn and scripting on top of the JVM and wanted to know if I can get my java code and javascripts to communicate more effectively.

I\'m using a 3rd

相关标签:
1条回答
  • 2021-02-06 09:25

    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).

    0 讨论(0)
提交回复
热议问题