2

動的に追加されたプロパティで取得できる 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から調べることができます

アドバイスありがとうございます!

4

1 に答える 1

1

これは可能ではないと思います。これは長年の機能リクエストですが、Jochenが言うように、Closuresをシリアル化する対象に問題があります...

于 2011-05-06T09:24:18.487 に答える