de-serialization not calling default constructor ?
Hi,
I have a strange problem with serialization (de-serialization, actually):
I have a bunch of classes that represent the model for my application.
These classes are organized as a complex tree and come in three flavors:
publicabstractclass AbstractIOCLeafimplements IOCElement{
private String name;
privatetransientboolean changed =false;
privatetransient LinkedList<ChangeListener> changeListeners;
protected AbstractIOCLeaf(){
super();
name =null;
changed =false;
changeListeners =new LinkedList<ChangeListener>();
}//needed for Serialzation
protected AbstractIOCLeaf(String name){
this();
this.name = name;
}
...
this class is a leaf: it cannot contain other sub-elements.
publicabstractclass AbstractIOCList<Textends IOCElement>extends AbstractIOCNodeimplements ComboBoxModel{
protected LinkedList<T> list =null;
protectedtransient List<ListDataListener> listListeners;
protectedabstract T newElement(String name);
protected AbstractIOCList(){super(); listListeners =new LinkedList<ListDataListener>();}
public AbstractIOCList(String name){
super(name);
list =new LinkedList<T>();
listListeners =new LinkedList<ListDataListener>();
}
...
This class holds a list of elements that are all equal.
and finally:
publicabstractclass AbstractIOCNodeextends AbstractIOCLeafimplements ChangeListener, ListDataListener{
protected AbstractIOCNode(){super();}
protected AbstractIOCNode(String name){
super(name);
}
...
This class holds elements that are all different.
The actual classesextends one of these following the pattern:
publicclass StateMachineextends AbstractIOCNode{
private StateList states =null;;
private EventQueue fEventQueue =null;
private StateMachine(){super();}
private StateMachine(String name){
super(name);
states = StateList.newInstance(this);
changed =false;
}
publicstatic StateMachine newInstance(String name){
StateMachine sm =new StateMachine(name);
sm.initialize();
return sm;
}
...
publicclass StateListextends AbstractIOCList<State>{
private StateMachine sm;
private StateList(){super("StateList"); sm =null;}
private StateList(StateMachine sm){
this();
this.sm = sm;
}
publicstatic StateList newInstance(StateMachine sm){
StateList list =new StateList(sm);
list.initialize();
return list;
}
...
etc. etc.
I do serialization callingObjectOutputStream.writeObject on the root object and (obviously) deserialize usingObjectOutputStream.readObject.
The process works, but it seems that the default constructors in particularAbstractIOCLeaf() is never called while deserializing. First hint to something amiss was the fact that I always had thetransient fieldchangeListeners remaining in its defaultnull state.
Further investigation involving debugging and breakpointing confirmedno default constructor is called in spite of thesuper(); calls.
What am I doing wrong?
Did I miss something about serialization (apparently so, but I cannot understand what!)?
Side issue:
I tried substitutingObjectOutputStream.writeObject withXMLEncoder.writeObject, but then I get the error: "Class sun.reflect.misc.Trampoline can not access a member of class com.softin.IOCbuilder.model.IOController with modifiers "private"".
Aren't those classes supposed to be equivalent?
Is there any (fast) way to desume the offending member?
Excuse me for the length of the post and
Thanks in Advance
Mauro

