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

Serialize( ) method (JsonSerializer)

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

Syntax

Serialize( INPUT object-reference AS Progress.Lang.Object,
INPUT output-stream AS Progress.IO.OutputStream )
object-reference
The class-based object to be serialized.
output-stream
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.JsonSerializer.
DEFINE VARIABLE myObj AS Acme.MyClass.

myObj = NEW Acme.MyClass().

mySerializer = NEW Progress.IO.JsonSerializer(FALSE).

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

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

Notes

*By default, all non-static, public data members and read-write properties are serialized. You can include protected and private data members, read-write properties, temp tables, and ProDataSets in serialization by defining them using the SERIALIZABLE option. See the DEFINE entry for each element for more details.
*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.
*By default, all non-static, public data members and read-write properties are serialized. You can include protected and private data members, read-write properties, temp tables, and ProDataSets in serialization by defining them using the SERIALIZABLE option. See the DEFINE entry for each element for more details.
*To be able to deserialize an object, the API for the object's class at the time of serialization must be compatible with the API for the class at the time of deserialization. At a minimum, the data members contained in the JSON string for that object should exist in the class, be serializable, and have compatible data types..
*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.
*Unlike binary serialization, you can only serialize one object at a time with JSON. If you need to serialize multiple objects, you must instantiate a serializer for each one.
*If the output stream is unknown or cannot be written to, the AVM raises an error.