editor › Globals › BaseSerializer
Class: BaseSerializer ‹SerializedClass, LatestSerializedObjectVersion, AllSerializedObjectVersions›
Base class to serialize something from/to plain javascript objects. Serializers must be added to the SerializationFactory which adds it to the SerializationContext.
remarks
Versioning the serialized interface should be done as follows:
1. Create a new interface for the next SerializedObjectVersion, e.g. MySerializedObjectV3
2. Set MySerializedObjectV3 as the LatestSerializedObjectVersion in the type parameters
3. Append this new type to the AllSerializedObjectVersions,
e.g. MySerializedObjectV1 | MySerializedObjectV2 | MySerializedObjectV3
This way, you can statically ensure, that all versions can still be deserialized.
See SerializationOrchestrator for more information about the serialization.
Type parameters
▪ SerializedClass
▪ LatestSerializedObjectVersion: object
▪ AllSerializedObjectVersions: object
Hierarchy
- BaseSerializer
↳ ArbitraryTransformsAnchorSerializer
↳ ExternalObjectDescriptorSerializer
↳ HalfEdgeMeshImplementationSerializer
↳ PositionableElementAnchorSerializer
↳ ReinforcementComponentSerializer
↳ RelativeTransformsAnchorSerializer
↳ SingleSurfaceMeshImplementationSerializer
↳ SvgSymmetryManagerSerializer
↳ PlateMergingComponentSerializer
↳ ManualNestingComponentSerializer
Index
Methods
- _deserializePlane
- _deserializeQuaternion
- _deserializeVector3
- _serializePlane
- _serializeQuaternion
- _serializeVector3
- deserialize
- linkDependencies
- serialize
- getSerializedClass
- getSerializedClassName
Methods
Protected _deserializePlane
▸ _deserializePlane(plane: ISerializedPlane): Plane
Defined in src/history/serialization/BaseSerializer.ts:155
Convenience method to serialize a Plane without invoking an extra serializer.
Parameters:
| Name | Type | Description |
|---|---|---|
plane |
ISerializedPlane | - |
Returns: Plane
Protected _deserializeQuaternion
▸ _deserializeQuaternion(quaternion: ISerializedQuaternion): Quaternion
Defined in src/history/serialization/BaseSerializer.ts:136
Convenience method to deserialize a Vector3 without invoking an extra serializer.
Parameters:
| Name | Type | Description |
|---|---|---|
quaternion |
ISerializedQuaternion | - |
Returns: Quaternion
Protected _deserializeVector3
▸ _deserializeVector3(vector: ISerializedVector3): Vector3
Defined in src/history/serialization/BaseSerializer.ts:115
Convenience method to deserialize a Vector3 without invoking an extra serializer.
Parameters:
| Name | Type |
|---|---|
vector |
ISerializedVector3 |
Returns: Vector3
Protected _serializePlane
▸ _serializePlane(plane: Plane): ISerializedPlane
Defined in src/history/serialization/BaseSerializer.ts:144
Convenience method to serialize a Plane without invoking an extra serializer.
Parameters:
| Name | Type | Description |
|---|---|---|
plane |
Plane | - |
Returns: ISerializedPlane
Protected _serializeQuaternion
▸ _serializeQuaternion(quaternion: Quaternion): ISerializedQuaternion
Defined in src/history/serialization/BaseSerializer.ts:123
Convenience method to serialize a Quaternion without invoking an extra serializer.
Parameters:
| Name | Type | Description |
|---|---|---|
quaternion |
Quaternion | - |
Returns: ISerializedQuaternion
Protected _serializeVector3
▸ _serializeVector3(vector: ReadonlyVector3): ISerializedVector3
Defined in src/history/serialization/BaseSerializer.ts:104
Convenience method to serialize a Vector3 without invoking an extra serializer.
Parameters:
| Name | Type |
|---|---|
vector |
ReadonlyVector3 |
Returns: ISerializedVector3
Abstract deserialize
▸ deserialize(serialized: AllSerializedObjectVersions): SerializedClass
Defined in src/history/serialization/BaseSerializer.ts:80
This method should instantiate the deserialized object and fill it with the information that can be retrieved from
the serialized object serialized. Any references to other objects, that depend on another Serializer (i.e. that
used enqueueObjectToSerialize in the serialize method) must be resolved in linkDependencies.
remarks
Classes might have to be adapted to allow for this separation between instantiation and initialization.
Parameters:
| Name | Type | Description |
|---|---|---|
serialized |
AllSerializedObjectVersions | the serialized object in POJO form, not as a string |
Returns: SerializedClass
linkDependencies
▸ linkDependencies(deserialized: SerializedClass, serialized: LatestSerializedObjectVersion, resolve: function): void
Defined in src/history/serialization/BaseSerializer.ts:93
This is invoked in a second pass when all objects have been instantiated. The passed resolve function does the
reverse of the enqueueObjectToSerialize function: It takes a name (e.g. Mesh1) and returns an object.
remarks
This object may not be fully populated yet. Some classes need to be adapted to allow instantiation in an
incomplete state (which sadly prevents immutability in some places).
Parameters:
▪ deserialized: SerializedClass
-
▪ serialized: LatestSerializedObjectVersion
-
▪ resolve: function
-
▸ (name: string): any
Parameters:
| Name | Type |
|---|---|
name |
string |
Returns: void
Abstract serialize
▸ serialize(target: SerializedClass, enqueueObjectToSerialize: function): LatestSerializedObjectVersion
Defined in src/history/serialization/BaseSerializer.ts:65
This method is invoked with the object to serialize and an enqueueObjectToSerialize function. This function accepts an object to be
serialized and returns the name of that serialized object (e.g. "Mesh1"). This allows expressing dependencies
between objects.
Parameters:
▪ target: SerializedClass
the object to be serialized
▪ enqueueObjectToSerialize: function
function to reference an object by the returned name in the serialization
▸ (o: any): string
Parameters:
| Name | Type |
|---|---|
o |
any |
Returns: LatestSerializedObjectVersion
the serialized object
Static getSerializedClass
▸ getSerializedClass(): object
Defined in src/history/serialization/BaseSerializer.ts:52
Return a reference to the class that is serialized by this Serializer.
Returns: object
Static getSerializedClassName
▸ getSerializedClassName(): string
Defined in src/history/serialization/BaseSerializer.ts:45
Overwrite in subclass.
Warning: Do not use getSerializedClass().name because the name is minified in production.
Returns: string
the (unique) name of the class that is serialized