W
wex
I am persisting a serialized object to a db. I have been able to
write and read it without problem until I recently did some
refractoring of my code and moved the class with gets serialized into
another package. Now I get a ClassNotFoundException. The class is
exactly the same just in another package. I didn't realize the
serialized object cared about it's package location. This is rather
annoying, does anyone know if there is a way around this problem.
Maybe another way to read and write it that doesn't make it so
sensitive? Below is my code to read and write the object.
//READ THE SERIALIZED OBJECT
byte[] buf = rs.getBytes("SERIALIZEDOBJECT");
if (buf != null)
{
ObjectInputStream objectIn = new ObjectInputStream(new
ByteArrayInputStream(buf));
this.serializeddata
=(mbs.data.serializeddata.SerializedDataObject)objectIn.readObject();
}
//write the serialized object
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(baos);
oout.writeObject(this.serializeddata);
oout.close();
statement.setObject(3, baos.toByteArray(), Types.OTHER);
write and read it without problem until I recently did some
refractoring of my code and moved the class with gets serialized into
another package. Now I get a ClassNotFoundException. The class is
exactly the same just in another package. I didn't realize the
serialized object cared about it's package location. This is rather
annoying, does anyone know if there is a way around this problem.
Maybe another way to read and write it that doesn't make it so
sensitive? Below is my code to read and write the object.
//READ THE SERIALIZED OBJECT
byte[] buf = rs.getBytes("SERIALIZEDOBJECT");
if (buf != null)
{
ObjectInputStream objectIn = new ObjectInputStream(new
ByteArrayInputStream(buf));
this.serializeddata
=(mbs.data.serializeddata.SerializedDataObject)objectIn.readObject();
}
//write the serialized object
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(baos);
oout.writeObject(this.serializeddata);
oout.close();
statement.setObject(3, baos.toByteArray(), Types.OTHER);