3

I've found the serialized and justSerialized methods on Object and already successfully serialized objects to files, but I cannot find a matching deserialize method.

Is there none or am I just too stupid to find it?

draegtun
  • 22,441
  • 5
  • 48
  • 71
Kutzi
  • 1,295
  • 1
  • 15
  • 19
  • never heard of iolanguage so far. this looks interesting – Aravind Yarram Dec 26 '10 at 10:24
  • 1
    Take a look at the file. I think the serialization process generates code to re-create the object. You just need to read and ``eval`` the result. Not sure, though. – nimrodm Dec 26 '10 at 11:16

1 Answers1

5

I think doString or doMessage should do what you need (though I can't confirm this at moment because I don't have Io running on this machine).

For eg:

doString( yourSerializedString )

or

doMessage( yourSerializedString asMessage )


Update - Can now confirm that doString or doMessage does work. Full example below:

Foo.io

Foo := Object clone do (
    name ::= nil
)

serialize.io

doRelativeFile("Foo.io")

baz := Foo clone setName("baz")

// serialize "baz" object to file
File with("serialized.data") open write(baz serialized) close

restore_object.io

doRelativeFile("Foo.io")

baz := doString(
    File with("serialized.data") open readLines join
)


In fact you can also deserialize the object with doRelativeFile or doFile:

baz := doRelativeFile("serialized.data")

Because serialized data is just Io code.

/I3az/

draegtun
  • 22,441
  • 5
  • 48
  • 71