I have Java class configuration which is serializable.
I want to create an instance of configuration which contains data of type string,Document (org.w3c.dom.Document) and save it into Db which is of type BLOB.
But when i am going to save it into the DB it’s throwing exception :
java.io.NotSerializableException: org.w3c.tidy.DOMElementImpl
My configuration class is:
public class Configuration extends Tag implements Serializable{
private Document doc = null ;
private String checkpoint=null;
}
I have used following code when saving configuration object to DB :
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(configuration);
byte[] confBytes = bos.toByteArray();
I am first converting it to byte array and then saving.
can anyone help me to get out of this issue..
This is saying that the
DOMElementImplclass is not marked asSerializable. Even though yourConfigurationclass implementsSerializable, all of the fields in your class need to do so as well. I assume thatDocumentis the field that is the problem. To quote from this serialization tutorial:Looking at the
DOMElementImplclass, it does implementSerializable. If you need to serialize this to a database then you will need to export it to another class before storing to the database.