Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:09:25+00:00 2026-06-04T15:09:25+00:00

Possible Duplicate: Convert a JSON string to object in Java? I’m working on a

  • 0

Possible Duplicate:
Convert a JSON string to object in Java?

I’m working on a scripting implementation for a video game written in Java.

I’m interested in being able to define a javascript object such as:

var obj = ({
    x: 1,
    a: "meh",
    onEvent: function(info) {
       //do stuff
    }
});

and passing it through a determined pipeline into Java land. Currently, in Java I’m receiving the object as a sun.org.mozilla.javasript.internal.NativeObject which doesn’t look very usable . Is there any way I can transfer the javascript into a Java object where I can access the data within? Specifically, without using GWT, as I’m not really working with web technologies.

EDIT FOR CLARITY:
I’m not passing in a string of Javascript code to the Java function ala JSON. I’m using the javax.script package to evaluate entire scripts. Within the script engine there are bindings to Java objects with methods I’d like to pass in my javascript object as a parameter.

thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:09:27+00:00Added an answer on June 4, 2026 at 3:09 pm

    I haven’t done much work with it, but the example from TFM seems like its not that difficult. Not sure what you’ve attempted already, but in any case:

    public static void main(String[] args) throws Exception {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
    
        // JavaScript code in a String. This code defines a script object 'obj'
        // with one method called 'hello'.        
        String script = "var obj = new Object(); obj.hello = function(name) { print('Hello, ' + name); }";
        // evaluate script
        engine.eval(script);
    
        // javax.script.Invocable is an optional interface.
        // Check whether your script engine implements or not!
        // Note that the JavaScript engine implements Invocable interface.
        Invocable inv = (Invocable) engine;
    
        // get script object on which we want to call the method
        Object obj = engine.get("obj");    // <---- THIS IS A JAVA.LANG.OBJECT
    
        // invoke the method named "hello" on the script object "obj"
        inv.invokeMethod(obj, "hello", "Script Method !!" );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: how to convert java string to Date object I have a form
Possible Duplicate: how to convert java string to Date object In my Java code
Possible Duplicate: Serializing to JSON in jQuery Convert Object to JSON string I want
Possible Duplicate: Convert JS object to JSON string I have a JSON object in
Possible Duplicate: Convert a String to Number - Java String s=1,000.0; how can I
Possible Duplicate: Convert String to code in Java Dynamic code execution on Java I
Possible Duplicate: C++ std::string conversion problem on Windows How to convert std::string to LPCSTR?
Possible Duplicate: Converting .NET DateTime to JSON How can I convert a date value
Possible Duplicate: How to convert from int to string in objective c: example code…
Possible Duplicate: How do you convert Byte Array to Hexadecimal String, and vice versa,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.