I am not so into JavaScript and I have this problem (I can solve it only using pure old JS and not third party library).
I have a JavaScript script processing a JSON object, in my script I have:
if(finalResponse.SubSpeciesInfo == null) {
log.info("NO SUBSPECIES");
finalResponse.SubSpeciesInfo.SubSpeciesList = [];
}
that check if this property of my original JSON object is null:
"SubSpeciesInfo": null
If this property of my JSON object is null it enter into the if block.
What I have to do here is to append the SubSpeciesList sub field that is an empty list.
But in this way it is not working, I obtain an error like:
ERROR {org.apache.synapse.mediators.bsf.ScriptMediator} - The script engine returned an error executing the inlined js script function mediate {org.apache.synapse.mediators.bsf.ScriptMediator}
com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EcmaError: TypeError: Cannot set property "SubSpeciesList" of null to "org.mozilla.javascript.NativeArray@37aa205f" (<Unknown Source>#106) in <Unknown Source> at line number 106
at com.sun.phobos.script.javascript.RhinoCompiledScript.eval(RhinoCompiledScript.java:68)
What is the problem? What am I missing? How can I fix this issue?