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

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to