I solve this problem by making the BufferedImage transient.
2013/5/27 Jonas <barney...@gmail.com> > Well, you can't serialize the BufferedImage, but maybe you can serialize > whatever data you've used to render BufferedImage's contents, > i.e. instead of saving the image, save whatever is necessary to recreate > the image? > Or, you could store the BufferedImage's content to an actual image file > (using ImageIO)? > > > On Wed, May 22, 2013 at 5:39 AM, smallufo <small...@gmail.com> wrote: > > > Thanks. > > But in my example , I cannot modify BufferedImage (to add a no-arg > > constructor) > > What should I do if I want to output a BufferedImage (and make back > button > > work) ? > > > > > > > > 2013/5/14 Jonas <barney...@gmail.com> > > > > > This could only work if BufferedImage itself had a no-arg constructor. > > > It is it the first non-serializable class in the hierarchy that needs > to > > > have it, > > > not the first serializable one, like in your example. > > > Besides, you would still lose all data stored in the BufferedImage's > > fields > > > (i.e. > > > the image stored in it). > > > > > > > > > On Mon, May 13, 2013 at 7:15 PM, smallufo <small...@gmail.com> wrote: > > > > > > > Today I encountered one famous deserialization problem : > > > > InvalidClassException : no valid constructor > > > > > > > > I googled and found some solution , but all are in-vain. > > > > The solution says the first non-serializable super class should > define > > a > > > > no-arg constructor. > > > > > > > > But I try to define a no-arg constructor to EACH class of the > > HIERARCHY , > > > > and EACH class implements Serializable... (which is not necessary , > > but I > > > > want to make it simple , to pinpoint the problem) > > > > > > > > My base class is an abstract class extends BufferedImage (java 2D) > > > > while BufferedImage is not Serializable > > > > So I make my abstract class implements Serializable and define a > no-arg > > > > default constructor. > > > > > > > > The total hierarchy is : > > > > public abstract class AbstractChart extends BufferedImage implements > > > > Serializable { > > > > public AbstractChart() { // I try to remove this > constructor > > , > > > > but in vain > > > > super(0 , 0, TYPE_INT_ARGB); > > > > } > > > > } > > > > > > > > and first child class : > > > > > > > > public class ChildChart extends AbstractChart implements > Serializable { > > > > public ChildChart() { > > > > super(); // or not calling super() > > > > } > > > > } > > > > > > > > and the grandson class : > > > > > > > > public class GrandsonChart extends ChildChart implements > Serializable { > > > > public GrandsonChart() { > > > > super(); // or not calling super() > > > > } > > > > } > > > > > > > > No matter I calls super() in ChildChart or GrandsonChart , > > > > > > > > Caused by: java.io.InvalidClassException: foobar.GrandsonChart; no > > valid > > > > constructor > > > > > > > > It happens when I click a button ,use ajax to paint this > GrandsonChart > > , > > > > and click another page , and use browser back . > > > > The browser will be redirected to /context/wicket/page?xxx (The error > > > page) > > > > The screen shows : > > > > Could not deserialize object using: > > > > class > > > > > > > > > > > > > > org.apache.wicket.serialize.java.JavaSerializer$ClassResolverObjectInputStream > > > > > > > > and in the console log , I can see this InvalidClassException is > > thrown. > > > > > > > > Any way to solve this problem ? > > > > (I've already added default no-arg constructor , and make each class > > > > implements Serializable , but still not working ) > > > > > > > > environment : > > > > Wicket version : 6.7 > > > > Resin 4.0.25 > > > > Java HotSpot(TM) 64-Bit Server VM 20.4-b02-402, 64, mixed mode, Apple > > Inc > > > > (It happens on Linux JDK too) > > > > > > > > > >