GWT Autobean - how to handle lists?

I am trying to evaluate the GWT Autobean function to decode / encode a JSON object for domain objects for REST calls.

Following the example: http://code.google.com/p/google-web-toolkit/wiki/AutoBean#Quickstart

I managed to convert a single JSON object to a domain object:

AutoBean<Person> personBean = AutoBeanCodex.decode(factory, Person.class, JsonResources.INSTANCE.json().getText()); 

where JsonResources.INSTANCE.json () returns a JSON string.

However, I was unable to convert the list of Person objects from JSON.

Would it be helpful if anyone has an example of this?

Thanks!

+7
source share
1 answer

Well, the only way I can think of is to create a special auto bank that will have the List<Person> property. For example:

 public interface Result { void setPersons(List<Person> persons); List<Person> getPersons(); } 

And an example json string:

 { persons:[ {"name":"Thomas Broyer"}, {"name":"Colin Alworth"} ] } 

UPDATE: The workaround when entering JSON is an array (as suggested by persons[0] in the comments). For example. JSON looks like this:

 [{"name":"Thomas Broyer"},{"name":"Colin Alworth"}] 

And the analysis code is as follows:

 AutoBeanCodex.decode(factory, Result.class, "{\"persons\": " + json + "}").getPersons(); 
+17
source

All Articles