Reputation: 641
is there any way to serialize an expando subclass which can be retrieved with dynamically added properties. with the example;
class Sexpando extends Expando implements Serializable{
//String testProp
static final long serialVersionUID = -2056428816613381087L
String toString() {
"an object of Sexpando - $serialVersionUID"
}
}
and
class SexpandoTest {
static main(args) {
def s = new Sexpando()
s.testProp = "small test string"
println s.properties
def file = new File('objects.dta')
def out = file.newOutputStream()
def oos = new ObjectOutputStream(out)
oos.writeObject(s)
oos.close()
def retrieved = []
file.eachObject { retrieved << it }
retrieved.each { println it.properties }
}}
i get the output:
[testProp:small test string]
[:]
i also tried same example with original testProp field of Sexpando object (it is commented out above)
Groovy's original Expando.java can be inspected from HERE
thank you for any advice!
Upvotes: 2
Views: 1310
Reputation: 171144
I don't think this is possible, it's a long standing feature request, but as Jochen says, there is an issue with what Closures should be serialized to...
Upvotes: 1