record TgoBsonSerializer

DescriptionHierarchyInternal Classes and RecordsInternal TypesFieldsMethodsProperties

Unit

Declaration

type TgoBsonSerializer = record

Description

Static class for serializing and deserializing to JSON and BSON format

Overview

Internal Classes and Records

TCustomSerializer = class abstract(TSerializer)

Internal Types

TConstructorProc = function(const AClass: TClass; const AAlloc: Shortint): TObject;
TCustomSerializerClass = class of TCustomSerializer;
TDeserializePropertyProc = procedure(const AProp: TPropertyInfo; const AInstance: TObject; const AReader: IgoBsonBaseReader);
TDeserializeVarProc = procedure(const AVar: TVarInfo; const AAddress: Pointer; const AReader: IgoBsonBaseReader);
TInitializeRecordProc = procedure(const ASelf: Pointer);
TSerializePropertyProc = procedure(const AProp: TPropertyInfo; const AInstance: TObject; const AWriter: IgoBsonBaseWriter);
TSerializeVarProc = procedure(const AVar: TVarInfo; const AAddress: Pointer; const AWriter: IgoBsonBaseWriter);

Methods

class procedure Serialize<T>(const AValue: T; out AJson: String); overload; inline; static;
class procedure Serialize<T>(const AValue: T; const ASettings: TgoJsonWriterSettings; out AJson: String); overload; inline; static;
class procedure Serialize<T>(const AValue: T; out ABson: TBytes); overload; inline; static;
class procedure Serialize<T>(const AValue: T; out ADocument: TgoBsonDocument); overload; inline; static;
class procedure Serialize<T>(const AValue: T; const AWriter: IgoBsonBaseWriter); overload; static;
class function TrySerialize<T>(const AValue: T; out AJson: String): Boolean; overload; inline; static;
class function TrySerialize<T>(const AValue: T; const ASettings: TgoJsonWriterSettings; out AJson: String): Boolean; overload; inline; static;
class function TrySerialize<T>(const AValue: T; out ABson: TBytes): Boolean; overload; inline; static;
class function TrySerialize<T>(const AValue: T; out ADocument: TgoBsonDocument): Boolean; overload; inline; static;
class function TrySerialize<T>(const AValue: T; const AWriter: IgoBsonBaseWriter): Boolean; overload; static;
class procedure Deserialize<T>(const AJson: String; var AValue: T); overload; inline; static;
class procedure Deserialize<T>(const ABson: TBytes; var AValue: T); overload; inline; static;
class procedure Deserialize<T>(const ADocument: TgoBsonDocument; var AValue: T); overload; inline; static;
class procedure Deserialize<T>(const AReader: IgoBsonBaseReader; var AValue: T); overload; static;
class function TryDeserialize<T>(const AJson: String; var AValue: T): Boolean; overload; inline; static;
class function TryDeserialize<T>(const ABson: TBytes; var AValue: T): Boolean; overload; inline; static;
class function TryDeserialize<T>(const ADocument: TgoBsonDocument; var AValue: T): Boolean; overload; inline; static;
class function TryDeserialize<T>(const AReader: IgoBsonBaseReader; var AValue: T): Boolean; overload; static;
class procedure RegisterSubClass(const ASubClass: TClass); static;
class procedure RegisterSubClasses(const ASubClasses: array of TClass); static;
class procedure RegisterCustomSerializer<T: record>(const ASerializerClass: TCustomSerializerClass); overload; static;
class procedure RegisterCustomSerializer(const AForType: PTypeInfo; const ASerializerClass: TCustomSerializerClass); overload; static;

Description

Internal Types

TConstructorProc = function(const AClass: TClass; const AAlloc: Shortint): TObject;
 
TCustomSerializerClass = class of TCustomSerializer;
 
TDeserializePropertyProc = procedure(const AProp: TPropertyInfo; const AInstance: TObject; const AReader: IgoBsonBaseReader);
 
TDeserializeVarProc = procedure(const AVar: TVarInfo; const AAddress: Pointer; const AReader: IgoBsonBaseReader);
 
TInitializeRecordProc = procedure(const ASelf: Pointer);
 
TSerializePropertyProc = procedure(const AProp: TPropertyInfo; const AInstance: TObject; const AWriter: IgoBsonBaseWriter);
 
TSerializeVarProc = procedure(const AVar: TVarInfo; const AAddress: Pointer; const AWriter: IgoBsonBaseWriter);
 

Methods

class procedure Serialize<T>(const AValue: T; out AJson: String); overload; inline; static;

Serializes a value to JSON format.

Parameters
AValue
the value to serialize. Must be a record, class or dynamic array.
AJson
is set to the serialized JSON output.
Exceptions raised
EgoBsonSerializerError
if type T is not serializable
class procedure Serialize<T>(const AValue: T; const ASettings: TgoJsonWriterSettings; out AJson: String); overload; inline; static;

Serializes a value to JSON format using custom output settings.

Parameters
AValue
the value to serialize. Must be a record, class or dynamic array.
ASettings
settings to use to customize the JSON output.
AJson
is set to the serialized JSON output.
Exceptions raised
EgoBsonSerializerError
if type T is not serializable
class procedure Serialize<T>(const AValue: T; out ABson: TBytes); overload; inline; static;

Serializes a value to BSON format.

Parameters
AValue
the value to serialize. Must be a record or class.
ABson
is set to the serialized BSON output.
Exceptions raised
EgoBsonSerializerError
if type T is not serializable
class procedure Serialize<T>(const AValue: T; out ADocument: TgoBsonDocument); overload; inline; static;

Serializes a value to a BSON document.

Parameters
AValue
the value to serialize. Must be a record or class.
ADocument
is set to the serialized document.
Exceptions raised
EgoBsonSerializerError
if type T is not serializable
class procedure Serialize<T>(const AValue: T; const AWriter: IgoBsonBaseWriter); overload; static;

Serializes a value using a writer interface.

Parameters
AValue
the value to serialize. Must be a record or class.
AWriter
the writer to serialize to.
Exceptions raised
EgoBsonSerializerError
if type T is not serializable
class function TrySerialize<T>(const AValue: T; out AJson: String): Boolean; overload; inline; static;

Tries to serialize a value to JSON format.

Parameters
AValue
the value to serialize. Must be a record, class or dynamic array.
AJson
is set to the serialized JSON output, or an empty string if serialization failed.
Returns

True on success, or False when type T is not serializable

class function TrySerialize<T>(const AValue: T; const ASettings: TgoJsonWriterSettings; out AJson: String): Boolean; overload; inline; static;

Tries to serialize a value to JSON format using custom output settings.

Parameters
AValue
the value to serialize. Must be a record, class or dynamic array.
ASettings
settings to use to customize the JSON output.
AJson
is set to the serialized JSON output, or an empty string if serialization failed.
Returns

True on success, or False when type T is not serializable

class function TrySerialize<T>(const AValue: T; out ABson: TBytes): Boolean; overload; inline; static;

Tries to serialize a value to BSON format.

Parameters
AValue
the value to serialize. Must be a record or class.
ABson
is set to the serialized BSON output, or nil if serialization failed.
Returns

True on success, or False when type T is not serializable

class function TrySerialize<T>(const AValue: T; out ADocument: TgoBsonDocument): Boolean; overload; inline; static;

Tries to serialize a value to a BSON document.

Parameters
AValue
the value to serialize. Must be a record or class.
ADocument
is set to the serialized document, or an empty document if serialization failed.
Returns

True on success, or False when type T is not serializable

class function TrySerialize<T>(const AValue: T; const AWriter: IgoBsonBaseWriter): Boolean; overload; static;

Tries to serialize a value using a writer interface.

Parameters
AValue
the value to serialize. Must be a record or class.
AWriter
the writer to serialize to.
Returns

True on success, or False when type T is not serializable

class procedure Deserialize<T>(const AJson: String; var AValue: T); overload; inline; static;

Deserializes data in JSON format.

Parameters
AJson
the JSON string to deserialize.
AValue
is set to the deserialized value. Must be a record, class or dynamic array. In case of a class, an instance of type T will be created if it is not already assigned.
Exceptions raised
EgoBsonSerializerError
if type T is not serializable or the JSON string is invalid.
class procedure Deserialize<T>(const ABson: TBytes; var AValue: T); overload; inline; static;

Deserializes data in BSON format.

Parameters
ABson
the BSON data to deserialize.
AValue
is set to the deserialized value. Must be a record, class or dynamic array. In case of a class, an instance of type T will be created if it is not already assigned.
Exceptions raised
EgoBsonSerializerError
if type T is not serializable or the BSON data is invalid.
class procedure Deserialize<T>(const ADocument: TgoBsonDocument; var AValue: T); overload; inline; static;

Deserializes data in a BSON document.

Parameters
ADocument
the document containing the data to deserialize.
AValue
is set to the deserialized value. Must be a record, class or dynamic array. In case of a class, an instance of type T will be created if it is not already assigned.
Exceptions raised
EgoBsonSerializerError
if type T is not serializable.
class procedure Deserialize<T>(const AReader: IgoBsonBaseReader; var AValue: T); overload; static;

Deserializes data using a reader interface.

Parameters
AReader
the reader to deserialize from
AValue
is set to the deserialized value. Must be a record, class or dynamic array. In case of a class, an instance of type T will be created if it is not already assigned.
Exceptions raised
EgoBsonSerializerError
if type T is not serializable or the reader contains invalid data..
class function TryDeserialize<T>(const AJson: String; var AValue: T): Boolean; overload; inline; static;

Tries to deserialize data in JSON format.

Parameters
AJson
the JSON string to deserialize.
AValue
is set to the deserialized value. Must be a record, class or dynamic array. In case of a class, an instance of type T will be created if it is not already assigned.
Exceptions raised
True
on success, or False when type T is not serializable or the JSON string is invalid.
class function TryDeserialize<T>(const ABson: TBytes; var AValue: T): Boolean; overload; inline; static;

Tries to deserialize data in BSON format.

Parameters
ABson
the BSON data to deserialize.
AValue
is set to the deserialized value. Must be a record, class or dynamic array. In case of a class, an instance of type T will be created if it is not already assigned.
Exceptions raised
True
on success, or False when type T is not serializable or the BSON data is invalid.
class function TryDeserialize<T>(const ADocument: TgoBsonDocument; var AValue: T): Boolean; overload; inline; static;

Tries to deserialize data in a BSON document.

Parameters
ADocument
the document containing the data to deserialize.
AValue
is set to the deserialized value. Must be a record, class or dynamic array. In case of a class, an instance of type T will be created if it is not already assigned.
Exceptions raised
True
on success, or False when type T is not serializable.
class function TryDeserialize<T>(const AReader: IgoBsonBaseReader; var AValue: T): Boolean; overload; static;

Tries to deserialize data using a reader interface.

Parameters
AReader
the reader to deserialize from
AValue
is set to the deserialized value. Must be a record, class or dynamic array. In case of a class, an instance of type T will be created if it is not already assigned.
Exceptions raised
True
on success, or False when type T is not serializable or the reader contains invalid data.
class procedure RegisterSubClass(const ASubClass: TClass); static;

Registers a known sub-class. See unit documentation for details.

Parameters
ASubClass
the sub-class to register
class procedure RegisterSubClasses(const ASubClasses: array of TClass); static;

Registers an array known sub-classes. See unit documentation for details.

Parameters
ASubClasses
the sub-classes to register
class procedure RegisterCustomSerializer<T: record>(const ASerializerClass: TCustomSerializerClass); overload; static;

Registers a custom serializer for a specific type. See unit documentation for details.

Parameters
T
the type for which to use the custom serializer.
ASerializerClass
the serializer class to use to (de)serialize values of type T.
class procedure RegisterCustomSerializer(const AForType: PTypeInfo; const ASerializerClass: TCustomSerializerClass); overload; static;

Registers a custom serializer for a specific type. See unit documentation for details.

Parameters
AForType
the type for which to use the custom serializer.
ASerializerClass
the serializer class to use to (de)serialize values of type AForType.

Generated by P2PasDoc 0.13.0 on 2017-04-25 12:54:26