Data.DBXJSONReflect.TConverter

From RAD Studio API Documentation
Jump to: navigation, search

System.TObjectTConverter

Delphi

TConverter<TSerial> = class abstract

C++

template<typename TSerial> class PASCALIMPLEMENTATION TConverter__1 : public System::TObject

Properties

Type Visibility Source Unit Parent
class public
Data.DBXJSONReflect.pas
Data.DBXJSONReflect.hpp
Data.DBXJSONReflect Data.DBXJSONReflect

Description

Represents the base converter class.

Any serializer needs to inherit from the TConverter class. TConverter provides the API events used by a marshaller class to serialize a user object.

Converters and reverters can be registered against a type and a field, or for a type. Any field declared of that type is processed by the provided user converter/reverter. A field registered converter/reverter takes precedence in front of a type converter/reverter.

A field converter can transform a field value into a string, an object, a list of strings, or a list of objects. The contract is that those transformed values will be passed as arguments to the correspondent reverter to reconstitute the field value.

A type converter can transform a value into a string, an object, a list of strings, or a list of objects. These will be passed as arguments to the type reverter that will reconstitute the original type instance.

For example, a TStringList field can be converted into an array of strings by a converter, and a reverter can use the list of strings to create and populate an instance of TStringList. This is the degree of complexity expected by a user-defined converter/reverter.

On predetermined situations, events are emitted. The following table contains the list of situations that can occur during marshalling.



Situation Event

A new object is encountered.

OnTypeStart

An already visited object is encountered.

OnRefType

A new object content was revisited.

OnTypeEnd

A new field is encountered.

OnFieldStart

A new field is visited.

OnFieldEnd

A string value is encountered.

OnString

A numeric value is encountered.

OnNumber

A nil value is encountered.

OnNull

A Boolean value is encountered.

OnBoolean

A list value is encountered.

OnListStart

A list is finished processing.

OnListEnd



The events are received by a TConverter instance. They are imbricated, depending on the structure of the user object. Based on the events ant their arguments, the TConverter instance builds an equivalent image of the user object.

The object image built by the converter can be used to reconstitute the original user object, using reverter events driven by an unmarshaller.

Note: These are the fields for which there is already a built-in conversion/reversion: integer, string, char, enumeration, float, object. For the following types, the field values are ignored and user conversion is expected: set, method, variant, interface, pointer, dynArray, classRef, array.

See Also