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: foobar.GrandsonChart; no valid

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:

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)

Reply via email to