pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill van Melle <bill.van.me...@gmail.com>
Subject Re: JSONSerializer and Collections
Date Mon, 07 Feb 2011 21:15:48 GMT
Yeah, we had a long exchange (and some bug fixes) about this a couple months
ago.  Java's type erasure means you can't get a Class object specialized to
your type, so there's a crufty workaround using a pivot utility class, which
I think goes like this:

  Type type = (new TypeLiteral<ArrayList<Person>>() {}).getType();

after which you can do new JSONSerializer(type).

Alternatively, you can create a trivial class:

  class ListOfPerson extends <ArrayList<Person> {

and then do new JSONSerializer(ListOfPerson).

On Mon, Feb 7, 2011 at 11:30 AM, anton dos santos <adsantos@free.fr> wrote:

> Hi
> i am using QueryServlet and WebQuery to exchange data between the server
> and the Pivot client, which works fine for simple beans.
> But I don't know how to instanciate the JSONSerializer when I want to send
> a collection of beans : let's say
> org.apache.pivot.collections.ArrayList<Person>.
> When I do :  new JSONSerializer(ArrayList.class) , the client receives an
> ArrayList of HashMap; but I'd like to get an ArrayList of Person.
> How can this be done?
> Regards
> Anton

View raw message