Question

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?

Was it helpful?

Solution

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top