Serializing a List

1,035 views
Skip to first unread message

mmoossen

unread,
Mar 8, 2010, 10:06:49 AM3/8/10
to Google Web Toolkit
Dear all!

i want to serialize a bean that has a field of type java.util.List<T>
but while serializing i get following error message:

com.google.gwt.user.client.rpc.SerializationException: Type
'java.util.Collections$UnmodifiableRandomAccessList' was not included
in the set of types which can be serialized by this
SerializationPolicy or its Class object could not be loaded. For
security purposes, this type will not be serialized.: instance = [...]

i think the problem is that on the server i use
Collections.unmodifiableList(..) or Collections.emptyList(..) to
populate that field, but the GWT compiler does not find those
subclasses.

any idea?

thanks in advance
Michael

rjcarr

unread,
Mar 8, 2010, 3:59:16 PM3/8/10
to Google Web Toolkit
The problem is likely exactly what you describe here: "but the GWT
compiler does not find those subclasses." More specifically, those
classes aren't part of the gwt jre emulation, so that's why you're
having problems.

For the unmodifiable list, I'd just suggest not sending your list
through that filter. If you need that functionality, you'll have to
create your own implementation.

For the empty list, I'm not really understanding the point. Couldn't
you just return "new ArrayList()"? I know that ArrayList is emulated,
so it would work.

mmoossen

unread,
Mar 9, 2010, 2:41:10 AM3/9/10
to Google Web Toolkit
Hi, rjcarr!

thanks for your answer.

the point is that on the server (and actually also on the client) that
field should be read-only.

i found the problem in
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/super/com/google/gwt/emul/java/util/Collections.java
line 114:
TODO: make the unmodifiable collections serializable

so i think i will forget trying to use my server-side beans for client
code.
i will just translate the server-side results to client-only beans.
it is just a lot of work (cpu-time) for nothing, but it would be the
same to convert them to JSON for other frameworks.

thanks
Michael

Eric

unread,
Mar 9, 2010, 11:19:39 AM3/9/10
to Google Web Toolkit

On Mar 9, 2:41 am, mmoossen <mmoos...@gmail.com> wrote:
> i found the problem inhttp://code.google.com/p/google-web-toolkit/source/browse/trunk/user/...


> line 114:
> TODO: make the unmodifiable collections serializable
>
> so i think i will forget trying to use my server-side beans for client
> code.
> i will just translate the server-side results to client-only beans.
> it is just a lot of work (cpu-time) for nothing, but it would be the
> same to convert them to JSON for other frameworks.

The Google Collections project advertises its ImmutableList<T> class
as being GWT-compatible. You might be able to resort to that project's
Lists.of() method instead of the JDK Collections.unmodifiableList()
method.

Respectfully,
Eric Jablow

mmoossen

unread,
Mar 10, 2010, 3:16:23 AM3/10/10
to Google Web Toolkit
thanks eric for the info.
that seems to be an interesting project.

Michael

Paul Stockley

unread,
Mar 10, 2010, 7:39:37 AM3/10/10
to Google Web Toolkit
I had exactly the same problem as this but it had nothing to do with
lists. The problem seemed to be that I was returning a type with a
generic argument i.e. Result<String> As soon as I removed the generic
part it worked.
Reply all
Reply to author
Forward
0 new messages