Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#196 Serialization exception due to QName

dom4j_1.6.x
open
None
5
2014-08-23
2011-06-21
ppiuser
No

Hello,

the class QName is not compliant to the java serialization spec which causes a MarshalException when passing an org.dom4j.Document as parameter in an EJB-Interface implementation. Adjusting the methods readObject(..) and writeObject(..) as shown below solves the problem:

private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();
    out.writeObject(namespace.getPrefix());
    out.writeObject(namespace.getURI());
}

private void readObject(ObjectInputStream in) throws IOException,
        ClassNotFoundException {
    in.defaultReadObject();
    String prefix = (String) in.readObject();
    String uri = (String) in.readObject();
    namespace = Namespace.get(prefix, uri);
}

As mentioned in the serialization spec the methods must call defaultReadObject() or defaultWriteObject() once before reading or writing from the stream.

Discussion