groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "" <>
Subject Implementing DeepClone with Traits - Issue with groovyProxy
Date Sun, 10 May 2015 17:39:39 GMT
I am trying to implement a DeepClone using traits. I borrows the
implementation from this stackoverflow answer

Is there a way to bypass the generated proxy? Or other implementation that
can avoid this error? My simplistic test code is as follow
(The real case is a map of lists, that's why I need a deep-clone)

Thanks in advance.

trait DeepCloneable {
    // implementation adapted from
    def deepClone() {
        def orig = this
        def bos = new ByteArrayOutputStream()
        def oos = new ObjectOutputStream(bos)
        oos.writeObject(orig); oos.flush()
        def bin = new ByteArrayInputStream(bos.toByteArray())
        def ois = new ObjectInputStream(bin)
        return ois.readObject()

def map = [name: "Fernando"] as DeepCloneable
def clone = map.deepClone()

View raw message