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 8662089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:39:04+00:00 2026-06-12T16:39:04+00:00

Update: I was wrong naming a plain JavaScript object as JSON object. Thanks to

  • 0

Update: I was wrong naming a plain JavaScript object as “JSON object”. Thanks to guys who pointed it out in comments below. So I edited the question to avoid further misunderstanding.

I wonder whether calling JavaScript function with JavaScript object (that can be described as JSON string) as an argument using netscape.javascript.JSObject is possible from Java. I tried the following code snippet:

JSObject.getWindow(MyApplet.this).call(jsFunctionName, jsArgs);

According to this article Java objects are passed to named JavaScript function as is and will be automatically converted to some JavaScript primitives depending on context they are used in. Does it mean that it is impossible to pass a real JavaScript object described as some JSON string to JavaScript function and I have to look for a workaround like preparing a JSON string as java.lang.String argument in Java and then parsing it in JavaScript function to get a plain JavaScript object?

  • 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-12T16:39:05+00:00Added an answer on June 12, 2026 at 4:39 pm

    It is better to refer to chapter: «19.3 LiveConnect Data Conversion».

    Every object passed within jsArgs is wrapped with JavaObject wrapper. In fact it is the same JavaScript object with all public properties and methods of underlying object available.


    E.g. if I have folowing Java class:

    public class MyJavaClass {
        public String name;
        public int number;
        public MyJavaClass(String n, int i) {
            name = n;
            number = num;
        }
    }
    

    And call JavaScript function:

    JSObject.getWindow(MyApplet.this).call("abFunc", new MyJavaClass("Kolya", 500));
    

    JavaScript function could look like:

    var abFunc = function(obj){
        numberPlusThousand = (1000 + obj.number);
        name = String(obj.name);
        ...
    };
    

    And you could convert it to JSON string like any other JavaScript object, if you want.


    Instances of JSObject class passed as arguments to call function will be converted to corresponding JavaScript objects. So, if you want to avoid JavaObject instaces occurence in your JavaScript code, you could try to create new JSObject instances like this:

    JSObject myJsObj = (JSObject) JSObject.eval("{}");
    

    And add new properties:

    myJsObj.setMember("name", JSObject.eval("'Kolya'"));
    myJsObj.setMember("number", 500);
    

    Or like this:

    myJsObj.eval("self.name = 'Kolya'");
    myJsObj.eval("self.number = 500");
    

    To my mind, it will be more convenient to represent JavaScript objects within Java as maps, pass them to JavaScript as JSON strings using library like Gson, and convert them to JavaScript objects using JSON.parse().

    Take a look at this Gson usage:

    Map m1 = ImmutableMap.of("id", "Kolya", "num", 500);
    Map m2 = ImmutableMap.of("marks", new byte[] {5, 4, 5, 3});
    Map m = ImmutableMap.of("m1", m1, "m2", m2, "l", ImmutableList.of("str", 234L, false));
    System.out.println(new Gson().toJson(m));
    // {"m1":{"id":"Kolya","num":500},"m2":{"marks":[5,4,5,3]},"l":["str",234,false]}
    

    ImmutableMap and ImmutableList are from Guava libraries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a simple SQL question - Bbut i can't figure out whats wrong UPDATE
how would I accomplish the following that are in the comments: UPDATE: Had wrong
UPDATE: appologies for the wrong place I chose to put stuff. I didn't notice
what wrong with this Query ??? i need this Query. UPDATE user_preferences SET user_preferences_value
What is wrong with the following PostgreSQL query? UPDATE project_project SET project_project.create_date = assignments.start_date
I'm trying to update one table based on values in another table. What's wrong
Updated: Thank you Rob W for pointing out there was nothing wrong with the
update: I mistyped 2 variables...so embarrassing. thanks everyone for the effort! sorry i find
UPDATE: Sorry I was wrong with my assumption of the problem. Its due to
I wanted to calculate the median I don't know what is wrong here UPDATE:

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.