Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I deserialize objects in Io?

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?

like image 254
Kutzi Avatar asked Mar 21 '26 05:03

Kutzi


1 Answers

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/

like image 55
draegtun Avatar answered Mar 24 '26 22:03

draegtun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!