2011-05-06 6 views
2

동적으로 추가 된 속성으로 검색 할 수있는 expando 하위 클래스를 직렬화하는 방법은 없습니다. 예제와 함께;Groovy Expando Serializable

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 } 
}} 

난 출력 얻을 : (가 상기 주석) 나도 Sexpando 객체의 원래 testProp 필드와 같은 예를 시도

[testProp:small test string] 
[:] 

Groovy의 원래 Expando.java를 fr에서 검사 할 수 있습니다. om HERE

조언 해 주셔서 감사합니다.

+1

좋은 클래스 이름 : –

+0

=) SerializedEXPANDO – hgoz

답변

1
나는 이것이 그것이 long standing feature request하지만 요헨 말한대로,로 폐쇄을 serialize해야하는지에 문제가있다, 가능하다고 생각하지 않습니다

...

+0

흠 , 괜찮아! 그래서 나는 그 문제를 이해한다. 또한 GroovyObjectSupport.java를 검사하여 metaClass 필드가 일시적인지 확인합니다. 따라서 직렬화 할 수 없습니다. 직렬화에 도전하는 MOP : D 다시 한 번 감사드립니다. – hgoz