I am trying to create a serializable interface implementation in groovy dynamically which could be send over the wire where it can be deserialized and executed with args. I have created anonymous interface implementation using map but it fails on serialization.
gcloader = new GroovyClassLoader()
script = "class X { public def x = [call: {y -> y+1}] as MyCallable }"
gclass = gcloader.parseClass(script)
x = gclass.newInstance().x
// serialzing x fails
I am not sure if a groovy closure is compiled to a random class name, which would make it impossible to deserialized even if it gets serialized. Is there a way to do this?