You can create an empty ObjectObject, fill it with FBSValues, and simply place it directly in the Map area:
ObjectObject myvar = new ObjectObject(); try { myvar.put("p1", FBSUtility.wrap("part 1")); myvar.put("p2", FBSUtility.wrap("part 2")); } catch (InterpretException e) { e.printStackTrace(); } Map<String, Object> applicationScope = ExtLibUtil.getApplicationScope(); applicationScope.put("myvarname", myvar);
When received later (as in the above examples), SSJS will see it as JSON, Java will see it exactly as it was saved.
If you need to store deeper hierarchies, you can put ArrayObject and ObjectObject instances inside ObjectObject in addition to the primitives, so like JSON itself, you can nest them as deep as you need.
Just remember to include only true JSON (strings, numbers, booleans, arrays, objects) if you store it somewhere higher than requestScope; in particular, FunctionObject does not implement Serializable, therefore JSON is safe for storage, JavaScript is not. Strictly speaking, it becomes toxic only when saved in viewScope in 8.5.2 and 8.5.3 (and even then only if the applicationβs save option is not set to store all pages in memory). But if IBM ever implements cluster support, then all objects stored in sessionScope and applicationScope must be serializable in order to provide cross-server public transport ... so in the interests of future design validation it is advisable to adhere to this principle for anything stored longer than the duration of a single request.
Tim tripcony
source share