GWT Serialization 2

January 4, 2008

GWT can serialize this class.

public MyClass  implements IsSerializable {
    public String myStr;
}

But if you change MyClass into the one below, GWT cannot serialize it and you’ll get the unhelpful error message: “Error: Type ‘foo.bar.MyClass’ was not serializable and has no concrete serializable subtypes”.

public MyClass  implements IsSerializable {
    public String myStr;
    public MyClass(String str){myStr = str;}
}

Want to know why? Because MyClass now lacks a no argument constructor.

I learned this from a thread on issue 540 at the Google Code website. The first post, which came during the GWT 1.3 time frame, rightly asks for a better error message when GWT cannot serialize something. Further down the thread, post say this problem is fixed. It seems to have been fixed before GWT 1.4. Nevertheless, the problem of the unhelpful serialization error message persists, at least when using IntelliJ IDEA 7.0.1 with the GWT Studio plugin.

The work around mentioned in the thread’s 2nd post still holds: any classe you want GWT to serialize must have a no arg constructor. GWT can serialize the class below.

public MyClass  implements IsSerializable {
    public String myStr;
    public MyClass(){}
    public MyClass(String str){  myStr = str; }
}

Entry Filed under: gwt, java. .

6 Comments Add your own

  • 1. Java developer  |  January 8, 2008 at 9:33 am

    Thanks for this entry. After an hour of looking at this, I finally did a google search and came to your site.

    Thanks for posting this….

    Reply
  • 2. Another java dev  |  January 30, 2008 at 2:12 pm

    Ditto what Java Developer said

    Reply
  • 3. yet another developer  |  April 28, 2008 at 10:45 am

    looks like a trifecta — ditto here too…thanks a bunch

    Reply
  • 4. cow  |  June 3, 2008 at 9:17 pm

    Cow says : I absolutely agree with this !

    Reply
  • 5. Dan Rowley  |  November 26, 2008 at 9:42 pm

    Thank you! I wasted 4 hours of my life trying to fix this until I stumbled upon this blog entry.

    Reply
  • 6. ultraklon  |  May 19, 2009 at 10:38 am

    Agree, Thank you!

    Reply

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent Posts

Recent Comments

Sridhar on Create an Executable Jar with…
ultraklon on GWT Serialization 2
ubuntudonateme on Amazing Ubuntu 8.10
Dan Rowley on GWT Serialization 2
cow on GWT Serialization 2

Categories

Meta