I have a problem persisting the Class object in the DB.
I tried to convert the object into a byte array using object ObjectArrayOutputStream
and ByteArrayOutputStream
as shown below and persisted it the byte array:
Class klazz = getClassForClassDef();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(klazz);
baos.toByteArray();
But I get an error shown below:
java.lang.ClassFormatError: Incompatible magic value 2901213189 in class file
I think that the way byte array was constructed has the problem. But I don't know how to create a correct .class
equivalent of the class object.