Try OpenEdge Now
skip to main content
ABL Reference
Class Properties and Methods Reference : Serialize( ) method (BinarySerializer)

Serialize( ) method (BinarySerializer)

Serializes an ABL class-based object to the specified binary stream.
Return type: VOID
Access: PUBLIC
Applies to: Progress.IO.BinarySerializer class


Serialize ( INPUT object-reference AS Progress.Lang.Object,
INPUT output-stream AS Progress.IO.OutputStream )
The class-based object to be serialized.
The stream to which the object-reference is serialized.
The following code sample serializes and deserializes myObj:
DEFINE VARIABLE myFileOutStream AS Progress.IO.FileOutputStream.
DEFINE VARIABLE myFileInStream AS Progress.IO.FileInputStream.
DEFINE VARIABLE mySerializer AS Progress.IO.BinarySerializer.

myObj = NEW Acme.MyClass().

mySerializer = NEW Progress.IO.BinarySerializer().

/* Serialize object */
myFileOutStream = NEW Progress.IO.FileOutputStream("MyClass.bin").
mySerializer:Serialize(myObj, myFileOutStream).

/* Deserialize object */
myFileInStream = NEW Progress.IO.FileInputStream("MyClass.bin").
myObj = CAST(mySerializer:Deserialize(myFileInStream), Acme.MyClass).


*All non-static data members, properties, temp tables, and ProDataSets of the object are serialized. This includes public, protected, and private data members. Object references in the data members of a class are also serialized.
*The following restrictions apply to objects being serialized:
*The object's class and all of the classes in its hierarchy must be marked as SERIALIZABLE. See the CLASS statement entry for more information.
*All of the object's data members that are themselves defined as class-based objects must be of class types that are also marked SERIALIZABLE. ABL enums are also allowed because they are implicitly serializable.
*To be able to deserialize an object, the API for the object's class at the time of serialization must match the API for the class at the time of deserialization. In other words, all the data members, properties, methods signatures and events must match exactly.
*The content of static data members is not serialized, and the state of queries, buffers, open files, streams, and event subscriptions, for example, are not maintained.
*Statically defined temp-tables and ProDataSets in user-defined classes are serialized, except for REFERENCE-ONLY tables.
*You can serialize multiple objects to one output stream before calling the Close( ) method. The objects must be deserialized in the same order as they were serialized.
*If the output stream is unknown or cannot be written to, the AVM raises an error.