-
Notifications
You must be signed in to change notification settings - Fork 861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix nested java objects in JSON.stringify #868
fix nested java objects in JSON.stringify #868
Conversation
map.forEach((k, v) -> { | ||
if (k instanceof CharSequence) { | ||
nObj.put(((CharSequence) k).toString(), nObj, v); | ||
nObj.put(((CharSequence) k).toString(), nObj, state.cx.getWrapFactory().wrap(state.cx, state.scope, v, v.getClass())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I be using ScriptRuntime.toObject
instead of calling wrap directly? Or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that Context.javaToJS does the right thing more than any of the alternatives I found. I didn't originally choose it because it's only available as a static method, and I already had a Context object, so I didn't think it needed to go through the process of finding the current Context.
I had overlooked until now PR #824, which looks very similar in function to #860 , and also appears to cover the shortcoming I mentioned above. I will take a closer look at it to see how the two approaches might be incorporated and possibly roll back some of my changes. I think for the time being this PR is still good as it corrects an issue in the current master branch. |
- Circular references are now caught - Enums and some Date and Time types are converted to strings Co-authored-by: Roland Praml <roland.praml@foconis.de>
149cbd3
to
7d3985e
Compare
This looks fine. Since @rPraml (who I can't seem to tag here) wrote the original PR I wonder if he can verify whether it fixes those issues? Otherwise, since I merged your other PR for this file, can you please resolve the conflicts and merge that one? |
Putting this one into draft for now. I'm still considering some other changes after the discussion on his PR. |
Closing this PR in favor of #875 |
I realized that my previous PR #860 did not allow for nested Maps and Lists. Can someone please review to see that I am now creating objects and arrays the correct way? I have a good deal of experience working with java objects in javascript, but very little in the other direction. The new tests are passing.