1 Language Model
2 Syntactic Forms
3 Datatypes
4 Structures
5 Classes and Objects
6 Units
7 Contracts
8 Pattern Matching
9 Control Flow
10 Concurrency
11 Macros
12 Input and Output
13 Reflection and Security
14 Operating System
15 Memory Management
16 Running PLT Scheme
Bibliography
Index
On this page:
define-serializable-class*
define-serializable-class
externalizable<%>
Version: 4.0.2

 

5.8 Object Serialization

(define-serializable-class* class-id superclass-expr

                                     (interface-expr ...)

  class-clause ...)

Binds class-id to a class, where superclass-expr, the interface-exprs, and the class-clauses are as in class*.

This forms can only be used at the top level, either within a module or outside. The class-id identifier is bound to the new class, and deserialize-info:@scheme [class-id] is also defined; if the definition is within a module, then the latter is provided from the module.

Serialization for the class works in one of two ways:

In the second case, a serializable subclass can implement externalizable<%>, in which case the externalize method is responsible for all serialization (i.e., automatic serialization is lost for instances of the subclass). In the first case, all serializable subclasses implement externalizable<%>, since a subclass implements all of the interfaces of its parent class.

In either case, if an object is an immediate instance of a subclass (that is not itself serializable), the object is serialized as if it was an immediate instance of the serializable class. In particular, overriding declarations of the externalize method are ignored for instances of non-serializable subclasses.

(define-serializable-class class-id superclass-expr

  class-clause ...)

Like define-serializable-class*, but with not interface expressions (analogous to class).

externalizable<%> : interface?

The externalizable<%> interface includes only the externalize and internalize methods. See define-serializable-class* for more information.