Is it possible to searialize/desearialize anonymous class in Java?
Example:
ByteArrayOutputStream operationByteArrayStream = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(operationByteArrayStream);
oos.writeObject(new Task() {
public void execute() {
System.out.println("Do some custom task"));
}
});
My problem is that I want to do some custom admin tasks so that i don't need a release for every task. So what i'm trying to do - is via Groovy scripting engine post custom task via HTTP endpoint and serialize them into db to run them in time.
It is possible, but dangerous. The name/number of anonymous classes is generated by the compiler and is based on the order they appear in the file. e.g. if you swap the order of two classes, their names will swap as well. (Classes are deserialized by name)