kurrazyman
unread,Sep 29, 2011, 5:37:08 PM9/29/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Google Web Toolkit
I have a situation where I am deserialiizing a JSON string into POJOs
using AutoBeans, this all works well apart from the scenario below: -
The JSON String sometimes contains objects in an array but may
sometimes just contain a single item (see below): -
Single include object in first group and array of include objects in
second group: -
{"groups":{"group":[{"id":49,"name":"Default Group","include":{"ref":
50,"type":"screen"}},{"id":83,"name":"Test","include":[{"ref":
50,"type":"screen"},{"ref":84,"type":"screen"}]}]}}
My Group Interface for AutoBeans looks like this: -
public interface Group {
public int getId();
public void setId(int groupId);
public String getName();
public void setName(String name);
public List<ScreenRef> getInclude();
public void setInclude(List<ScreenRef> screenRefs);
public TabBar getTabBar();
public void setTabBar(TabBar tabBar);
}
As you can see it is expecting to find a JSArray for the include
variable, but I cannot guarantee the JSON format. I have also
discovered that if the first Group object that is deserialized
contains an array of include objects then any subsequent Group object
can have either a single include object or an array of include objects
(not sure of why this is but I imagine it's something to do with the
way AutoBeans works), the dilemma I have is: -
1). Is this a bug with AutoBeans (should it always be able to convert
a singleton into a list if that's what is defined in the interface -
seems like it is possible in certain situations as explained above)?
2). Should I look to change my JSON server output so that even if a
single object is returned it is still wrapped in an array?
3). Is there a clever trick I am missing with AutoBeans that will
allow me to deal with this variation?
Any help would be much appreciated