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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:11:57+00:00 2026-06-16T15:11:57+00:00

I need to work with data returned from a service which has a more

  • 0

I need to work with data returned from a service which has a more complex JSON structure than the examples provided in the GXT documentation and thus far I cannot find any instructions or example which demonstrates how this might be accomplished.

The JSON contains multiple key/value pairs, but some of the key/value pairs are collections. I can have all of the data returned to me in one call from the service in the proper structure, but there does not appear to be a way to parse the data into separate entities. In my particular case I am attempting to configure a loader which will process one of the collections but I also need other key/value pairs from the same message (it is not ok to have the loader make one call and then have another call made for the same data and retrieve the other key/value pairs). Is there any way to accomplish this using GXT3?

Example: let’s assume I can make a request from a server which returns JSON containing the name of an author along with a collection of the books the author has written. I want to display the author’s name above a grid which lists the books. I want only one request made to the server and then have my view display the author in one component and the book list in a grid. Assume I need a loader instead of just a store as the grid may have to make additional calls (e.g. if it is a paging grid, livegrid, etc.).

Example JSON: (one JSON message returned with and author element along with a collection of book elements – I’ve indented the JSON to illustrate the structure)

{ "returnData" : 
  {"author" : "AuthorName"}, 
  {"books" : 
     {"id" : "1", "name" : "Book1"},{"id" : "2", "name" : "Book2"}
  }
}

Using the example for JsonReader (see the javadoc for an example) I can receive the request and parse the links into a collection using AutoBeans. This works fine when I need to have those retrieved and parsed in a loader. However, if I do that then the other properties are ignored. I currently don’t see any way to parse the other values in the same request so they can be used elsewhere. My example code for the collection processing is below:

// this is the root JSON object, the AuthorRecord
public interface AuthorRecord {
  @PropertyName(value="author")
  String getAuthor();
  @PropertyName(value="author")
  void setAuthor(String author);
  @PropertyName(value="books")
  List<Book> getBooks();@
  @PropertyName(value="books")
  void setBooks (List<Book> books);
}

// models the book objects returned
public interface Book {
 @PropertyName(value="id")
 String getId();
 @PropertyName(value="id")
 void setId(String id);
 @PropertyName(value="name")
 String getName();
 @PropertyName(value="name")
 void setName(String name);
}

public interface ReturnData {
  AuthorRootObject getAuthorRoot();
}

public interface LibraryAutoBeanFactory extends AutoBeanFactory {
  AutoBean<ReturnData> authorRecord();
 AutoBean<ListLoadConfig> loadConfig();
}

public class ReturnDataJsonReader extends JsonReader<ListLoadResult<Book>, 
  ReturnData> {
    public ReturnDataJsonReader(AutoBeanFactory factory, 
      Class<ReturnData> rootBeanType) {
        super(factory, rootBeanType);
    }

    @Override
    protected ListLoadResultBean<Book> createReturnData(Object loadConfig, 
      ReturnData incomingData) {
        return new ListLoadResultBean<Book>(incomingData.getBooks());
    }
}
  • 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-16T15:11:58+00:00Added an answer on June 16, 2026 at 3:11 pm

    The problem I was having was that I need to have a view that includes a grid (paging grid, etc.) which lists out the books, while having the Author’s name sit above the grid. I wanted to get all of this information (or at least the first page of results) with only one request to the server since the JSON message contains all the information I need to accomplish this. The problem is that the loader makes the request and receives the response, and it expects that the reader it will use is going to process a collection. In my case, I need the loader to process the collection of books but also populate another data field. The solution I found was to create an arbitrary collection to pass to the loader and then implement my own load handler to process the return object as needed.

    1.The JSON being returned is really just one object of type ReturnData. The extended JsonReader could process this using AutoBeans, but if the reader is to be used for the loader, it needs to return a collection. Therefore, override the createReturnData() method to return a collection of one object.

    public class ReturnDataJsonReader extends JsonReader<ListLoadResult<AuthorRecord>, 
      ReturnData> {
    
      public ReturnDataJsonReader(AutoBeanFactory factory, Class<ReturnData> rootBeanType) 
      {      
        super(factory, rootBeanType);   
      }    
    
      @Override   
      protected ListLoadResultBean<AuthorRecord> createReturnData(Object loadConfig,
          ReturnData incomingData) {       
    
        List<AuthorRecord> authorDataCollection = new ArrayList<AuthorRecord>();
        authorDataCollection.add(incomingData);
        return authorDataCollection;    
      }
    }
    

    2.The LoadHandler used in the examples takes a ListStore as an input and populates it with the results from the loader. Since the return object is not what we want populating the loader, and since we need to populate another property on the view, create your own LoadHandler to take the objects needed as input and populate them:

    View Class Example:

    public class ExampleViewClass {
     // truncating most of the code in here for brevity
     // note some of the objects referenced here reference objects in the question
     private String authorName;
     private ListStore<Book> bookList;
    
     // IMPORTANT - create your own LoadHandler
     private class LibraryLoadResultistStoreBinding<C, M, D extends
        ListLoadResult<AuthorRecord>> implements LoadHandler<ListLoadConfig, 
        ListLoadResult<AuthorRecord>> {
    
          private final ListStore<Book> bookStore;
          private final String authorName;
    
          public LibraryLoadResultistStoreBinding(ListStore<Book> books, String author) {
              this.bookStore = books;
              this.authorName = author;
          }
    
          @Override
          public void onLoad(LoadEvent<ListLoadConfig, ListLoadResult<AuthorRecord> event) 
          {
            // the response object
            AuthorRecord response = event.getLoadResult().getData().get(0);  
            bookStore.replaceAll(response.getBooks());
            author = response.getAuthor();
          }
       }
    
       // example uses an HttpProxy but that's not required
       public void populateView() {
         LibraryAutoBeanFactory factory = GWT.create(LibraryAutoBeanFactory.class);
         ReturnDataJsonReader reader = new ReturnDataJsonReader(factory, ReturnData.class);
         String path = "http://path.to.resource/getinfo";
         RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, path);
         HttpProxy<ListLoadConfig> proxy = new HttpProxy<ListLoadConfig>(builder);
    
         final ListLoader<ListLoadConfig, ListLoadResult<AuthorRecord>> loader = new       
           ListLoader<ListLoadConfig, ListLoadResult<AuthorRecord>> (proxy, reader);
    
         loader.useLoadConfig(ReturnDataAutoBeanFactory.instance.loadConfig().as();
    
         loader.addLoadHandler(new LibraryLoadResultistStoreBinding<ListLoadConfig, 
           AuthorRecord, ListLoadResult<AuthorRecord>>(bookList, authorName);  
         // pass in the objects to be populated
    
         loader.load();  // fire the loader
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am planning to work in TRIE data structure for which I need a
I am successfully retrieving JSON data from a web service with GET using Restkit's
I need to call a web service from javascript that returns a JSON array
I need to work out the best way to read data that is being
For some graphics work I need to read in a large amount of data
I'm trying to work on this website wherein I need to filter the data
I need to work with assets in my assets folder from within C/C++ code.
I need to work with a third-party Java library from .NET. Can anyone recommend
I have an array being returned from the database that looks like so: $data
Suppose I get data from a service (that I can't control) as: public class

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.