動的に追加されたプロパティで取得できる expando サブクラスをシリアル化する方法はありますか。例を挙げて;
class Sexpando extends Expando implements Serializable{
//String testProp
static final long serialVersionUID = -2056428816613381087L
String toString() {
"an object of Sexpando - $serialVersionUID"
}
}
と
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 }
}}
私は出力を取得します:
[testProp:small test string]
[:]
Sexpandoオブジェクトの元のtestPropフィールドでも同じ例を試しました(上記でコメントアウトされています)
Groovy のオリジナルの Expando.java はHEREから調べることができます
アドバイスありがとうございます!