How to make JSON.stringify work with NativeJavaArray?

I have a script that runs on the NetSuite platform, on which I am sure that 99% uses the Rhino JavaScript engine. I am trying to get the same script to work locally, but there is a problem with calling JSON.stringify on a wrapped Java array. In both environments, the array is of the [object JavaArray] , but while the Java array builds correctly on NetSuite, my local Rhino context says:

org.mozilla.javascript.EvaluatorException: Java class "[Ljava.lang.String;" does not have a public instance field or method named "toJSON".

At first I thought that they added the NativeJavaArray class using the toJSON method and returned it through a custom WrapFactory , but this does not seem like there is no toJSON method on the returned object.

Is there an option I need to configure for Java arrays to work with JSON methods? I would have to get around this by adding toJSON to the NativeJavaArray subclass, as I mentioned above, but I would like to be as compatible with NetSuite as possible.

+7
java json javascript arrays rhino
source share

No one has answered this question yet.

See related questions:

7728
How to redirect to another web page?
7649
How do JavaScript locks work?
7494
How to remove a specific element from an array in JavaScript?
7432
How to check if a string contains a substring in JavaScript?
7428
How to check if an element is hidden in jQuery?
5722
How to remove a property from a JavaScript object?
3714
How to check if an array contains a value in JavaScript?
3515
How to make the first letter of a string in uppercase in JavaScript?
2895
How to add something to an array?
2633
How to check for empty javascript object?

All Articles