File marshalling and unmarshalling exception
Hello All,
I just want to know that if I have an object which is serialized and another object which is not serialized then it is mandatory to serialize that object in the current example
For example
ArrayList is serialized by default.
So can this particular example run.
class ABC {
void go(){
}
}
ArrayList a = new ArrayList();
a.add(new ABC());
Do I need to serialize ABC also ?.
Thanks and regards,
Sachin
> Why it has to be serialize. If ArrayList is
> serializable then can't it hold the ABC object with
> it ?.
It can hold it but it can't serialize it.
The concept is dead simple really. If you want to Serialize a class then it must implement Serializable. It doesn't matter what the class is inside of or how many classes you have or anything else. Each and every class you want to serialize must implement Serializable.
> Means seems I am confused with serialization.
> Does anyone have a good tutorial on serialization ?.
I don't think you really need a tutorial for a straightforward concept like this but http://java.sun.com/docs/books/tutorial/essential/io/providing.html
The thing is that we tried to serialize the object ABC which was added in ArrayList. but it was giving Unmarshalling exception.
If a class implements Serializable then it has to marshalling as well as unmarshalling.
This ArrayList is passed to the EJB method as an arguement.
Thus it becomes
EBJImpl{
createABC( ArrayList al){
/// impl.
}
}
ArrayList has ABC object which is serializable but it is giving unmarshalling exception.
Any help in that ?.
regards,
Sachin
> If a class implements Serializable then it has to
> marshalling as well as unmarshalling.
Are you aware that implementing Serializable means more than writing "implements Serializable"? You have to make sure that everything ABC refers to either implements Serializable as well - the entire reference tree, or has to be declared transient.