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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:47:11+00:00 2026-06-17T04:47:11+00:00

I fill an JSONArray (org.JSON) on my GWT server side, then want to use

  • 0

I fill an JSONArray (org.JSON) on my GWT server side, then want to use the object on the client side. When I use a JSONObject (or Array) in my shared package, I get the exception that there was no source found (while it works on the server). Thus, I presume it cannot be used client side, or shared (could not confirm that despite googling).

Since shared would not use JSONObject, I presumed JSNI would work in shared. I have read into GWT overlay types on google developer and here on stackoverflow, and have made one in my shared package. However, since it is JSNI, it is not usable on the server. Therefore, I try to pass the JSONObject.toString() to my shared class, then use it as parameter for calling the following JSNI method:

public native UserOverlay getUser(String jsonObj) /*-{
    return jsonObj;
}-*/;

the call:

UserOverlay user = getUser(jsonobj);

However, this gives an UnsatisfiedLinkError at the location of the call, which as far as I know means that the JSNI method was not found, meaning that the shared package does NOT work with JSNI.

Conclusion

I need a method to use my JSON data on both Client, shared and server. If that method differs, then I need a way to convert one method to the other. I have seen threads that handle converting from overlay types to JSONObject, but not the other way around.

  • 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-17T04:47:12+00:00Added an answer on June 17, 2026 at 4:47 am

    If you’re referring to Crockford’s JSON implementation for Java, the reason it can’t be used on the client code is that it needs to be emulated first. For your purposes, you’d wanna use a different approach;

    Have the server returning a JSON text response (over HTTP, naturally), request it via XHR on the client, and than use the response in its raw form — as JSON is a subset of JavaScript’s literal object notation, it can be used transparently within JavaScript code.

    To implement this approach in GWT, create a servlet that returns the JSON as text (outputs it to the response’s writer). This servlet can than be called from the client using RequestBuilder (which wraps XHR), and overlay types can be used to convert each JSON response to Java managed objects according to its contract.

    The Google Developer documentation offers a tutorial on Retrieving JSON, discussing just that. I’ll encompass the highlights and some snippets, just for the sake of completeness:

    1. Create a servlet serving JSON

      Don’t forget to configure the webapp’s deployment descriptor (web.xml) accordingly.

      public class JsonDataServlet extends HttpServlet {
      
          @Override
          protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                  throws ServletException, IOException {
      
              PrintWriter out = resp.getWriter();
              out.println('{');
              // fill with JSON construct
              out.println('}');
              out.flush();
          }
      
      }
      
    2. Construct the overlay types according to the response’s interface

    3. Create client side utilities to convert the JSON response to a concrete JavaScriptObject

      The tutorial suggests the use of eval() inside a JSNI method, but I prefer to utilize JSONParser.parseStrict() as it will first try and call JavaScript’s JSON.parse() on supporting browsers.

      public static UserOverlay asUserOverlay(String json) {
          JSONValue jsonVal = JSONParser.parseStrict(json);
          JSONObject jsonObj = jsonVal.isObject();
          UserOverlay userOverlay = (UserOverlay) jsonObj.getJavaScriptObject();
      }
      

      Note: If you’re gonna use the eval() implementation anyway, the json argument needs to be wrapped in parentheses, i.e. eval('(' + json + ')').

    4. Call the servlet

      RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, GWT.getModuleBaseURL() + "path/to/servlet");
      rb.setCallback(new RequestCallback() {
      
          public void onError(Request request, Throwable exception) {
              // do something
          }
      
          public void onResponseReceived(Request request, Response response) {
              if (200 == response.getStatusCode()) {
                  UserOverlay userOverlay = asUserOverlay(response.getText());
                  // continue handling
              }
          }
      });
      rb.send();
      

    References on the Google Web Toolkit documentation

    • Retrieving JSON Data
    • Working With JSON
    • Communicate With A Server
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, Im getting a JSON from a REST server and I want to fill
I'm trying to loop through an JSON array in PHP and fill a fpdf
How Can i fill an array that defined in javascript with c# in behind
i want to use jquery ui auto complete plugin in asp.net. this is my
I fill up a List<> with an object that has properties. I can bind
Given: I fill up an array of handles with auto reset events and pass
I want to fill a polygon shape that I have drawn via Core Graphics
I want to fill a region using Graphics.fillRoundRect(), but I want a rectangle in
I want to fill a bean list property using Spring properties place holder. Context
Can someone help me figure out why the json array I have is not

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.