Try OpenEdge Now
skip to main content
Object-oriented Programming
Programming with Class-based Objects : Serialization and deserialization : Deserializing from a file
 

Deserializing from a file

To deserialize an instance:
1. Instantiate a variable of type Progress.IO.BinarySerializer (or Progress.IO.JsonSerializer).
2. Instantiate a variable of type Progress.IO.FileInputStream with your target filename as a parameter. This class provides functionality for reading from the file.
3. Invoke the Deerialize( ) method of your Progress.IO.BinarySerializer instance and pass it the filename from which the object will be deserialized. The the Deerialize( ) method returns an instance of type Progress.Lang.Object, so you must use the CAST function to set the deserialized object to the correct type.
4. Invoke the Close( ) method of the Progress.IO.FileInputStream object.
The following code example shows myObj, an instance of Acme.MyClass, being deserialized from a binary file MyClass.bin. The corresponding steps are numbered with comments.
DEFINE VARIABLE myFileInStream AS Progress.IO.FileInputStream.
DEFINE VARIABLE mySerializer AS Progress.IO.BinarySerializer.

DEFINE VARIABLE myObj AS Acme.MyClass.

myObj = NEW Acme.MyClass().

/* 1 */
mySerializer = NEW Progress.IO.BinarySerializer().

/* 2 */
myFileInStream = NEW Progress.IO.FileInputStream("MyClass.bin").

/* 3 */
myObj = CAST(mySerializer:Deserialize(myFileInStream), Acme.MyClass).

/* 4 */
myFileInStream:Close().
For full descriptions of all the classes and methods used in serializing and deserializing objects, see their entries in OpenEdge Development: ABL Reference.