Ubuntu insights, Programming in groovy, java, et als!

Monday, September 19, 2011

Serializing objects in Groovy

Never came across a more sexier way to serialize objects. Thanks to groovy goodness.


def map1 = ['1':'one']
def map2 = ['2':'two']

def file = new File("C:/serializedObjects.txt")

file.withObjectOutputStream { out ->
    out << map1
    out << map2          
}
                     
file.withObjectInputStream(getClass().classLoader){ ois ->
    ois.eachObject{
        println it                  
    }
}      

0 comments:

Post a Comment