enum serialization

1,076 views
Skip to first unread message

mbstiburon

unread,
Jul 27, 2010, 12:03:03 AM7/27/10
to Google Web Toolkit
I have classes with inner enums such as
public class Foo implements java.io.Serializable {
public enum Status {
ACTIVE, INACTIVE, NA
}

private Status status;
public Foo() {}

public Status getStatus(){
return this.status;
}
....
}

When I compile (gwtc), it does not complain; however, I get the
following exception during runtime.
....
Caused by: com.google.gwt.user.client.rpc.SerializationException: Type
'com.mycompany.gwt.Foo$Status' 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 = ACTIVE
...

Any idea?
Does gwt not able to serialize enums defined as an inner class? Do I
have to create top level enum classes?

BTW, I am using GWT 2.0.3 on OS X.

Any help on this would be greatly appreciated.

Prashant

unread,
Jul 27, 2010, 11:15:30 AM7/27/10
to google-we...@googlegroups.com
try

public enum Status implements java.io.Serializable {
ACTIVE, INACTIVE, NA
}

-- 
Prashant


Mike Heath

unread,
Jul 28, 2010, 12:35:17 AM7/28/10
to google-we...@googlegroups.com
All enum extend java.lang.Enum which implements java.io.Serializable so explicitly implementing Serializable shouldn't make a difference.

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

Raphaël Brugier

unread,
Jul 28, 2010, 10:39:08 AM7/28/10
to Google Web Toolkit
The serialization of inner enum works for me,

Be sure to have a default constructor in your enum.
Maybe also non-final fields.

Does your class is on a serializable package, usually the client or
shared ?

On 28 juil, 06:35, Mike Heath <mhe...@apache.org> wrote:
> All enum extend java.lang.Enum which implements java.io.Serializable so
> explicitly implementing Serializable shouldn't make a difference.
>
>
>
> On Tue, Jul 27, 2010 at 9:15 AM, Prashant <nextprash...@gmail.com> wrote:
> > try
>
> > public enum Status *implements **java.io.**Serializable* {
> >  ACTIVE, INACTIVE, NA
> > }
>
> > --
> > Prashant
> >www.claymus.com
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-we...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-web-tool...@googlegroups.com<google-web-toolkit%2Bunsubs cr...@googlegroups.com>
> > .

Rodrigo

unread,
Aug 10, 2010, 5:52:23 AM8/10/10
to Google Web Toolkit
I'm running into the same problem...

I have an inner enum inside a class in the shared package (which is
accessible to the client).

I tried making the enum implement IsSerializable, Serializable, adding
a default constructor, to no avail...

BTW, my code works in development mode, presumably because it actually
runs from the java code instead of from javascript (right?). But in
production mode, it fails. It actually fails silently, which made it
even harder to diagnose this problem, but that's a different story...

Any ideas?

On Jul 28, 10:39 am, Raphaël Brugier <raphael.brug...@gmail.com>
wrote:
> The serialization of innerenumworks for me,
>
> Be sure to have a default constructor in yourenum.
> Maybe also non-final fields.
>
> Does your class is on a serializable package, usually the client or
> shared ?
>
> On 28 juil, 06:35, Mike Heath <mhe...@apache.org> wrote:
>
>
>
> > Allenumextend java.lang.Enumwhich implements java.io.Serializable so
> > explicitly implementing Serializable shouldn't make a difference.
>
> > On Tue, Jul 27, 2010 at 9:15 AM, Prashant <nextprash...@gmail.com> wrote:
> > > try
>
> > > publicenumStatus *implements **java.io.**Serializable* {

vikash joshi

unread,
Mar 5, 2016, 5:38:34 PM3/5/16
to GWT Users
Even i am facing the same issue with GWT 2.6

I have a class in shared package that implements Serializable but it has inner Enums which also has a default constructor and which implements Serializable interface but still i get Serializable Exception when i try to use the Parent class during RPC call.

Gilberto

unread,
Mar 8, 2016, 12:39:24 PM3/8/16
to GWT Users
When I used GWT-RPC (nowadays I use REST) I solved the problem simply by not using inner enums. Another way is to overwrite the server code that handles the serialization policy to skip the check of your enums.
Reply all
Reply to author
Forward
0 new messages