This code ...
class A implements Serializable{ String str int n } try{ def a= new A(str:'abc', n:7) def out= new ObjectOutputStream(new FileOutputStream('serializedObject.obj')) out.writeObject(a) out.close() }finally{} try{ def inp= new ObjectInputStream(new FileInputStream('serializedObject.obj')) def a2= inp.readObject() inp.close() }finally{}
... causes an error ...
java.lang.ClassNotFoundException: A at java_io_ObjectInput$readObject.call(Unknown Source) at otherRun.run(otherRun.groovy:16)
... when trying to reload an object in the second try block. It works fine when the class is a predefined class like java.util.List. The code above also works fine when converting a string for a string in Java .
How can I make it work in Groovy?
source share