0

I have a use case where I have a java Map which I convert into ProxyMap, use that map in javascript using context.eval and then create a new object in js (nested json). Now I want to use the object that was created in javascript back in java preferably a Map.

Now my js created object is dynamic and I do not know what all fields might be present.

So basically what I am doing is:

  1. context.getBindings("js").putMember("input", ProxyObject.fromMap(map));
  2. Value js = context.eval("js", "var obj = {'a':input['type']};");
  3. Now I need to get this obj as a Map in Java.

From what I have found out is that I can access the fields of obj in java using getMember but as obj can be dynamic and can be quite complex as well, I was hoping that there might be another way out?

1 Answer 1

3

You can convert to a Map using the Value.as(Map.class) method.

Something like:

 assert context.eval("js", "({foo:'bar'})").as(Map.class).get("foo").equals("bar");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.