Table of Contents

TInstanceTypeSerialization Enumeration

Controls when the $type discriminator is emitted for polymorphic objects.

Remarks

This setting is relevant when serializing objects that may be of a derived type. The $type discriminator allows the deserializer to reconstruct the correct runtime type, and is mostly used by the XData client deserializer to know which type to instantiate when deserializing a polymorphic object. Using Never makes the output JSON cleaner but may cause deserialization to fail if the runtime type is not the same as the declared type. It's recommended to not use Never unless you are not going to deserialize objects from Delphi client, or if you are sure that the runtime type will always match the declared type.

Syntax

Unit: Bcl.Json.Converters

Members

Name Value Description
Always 0 Always emit the $type discriminator.
IfNeeded 1 Emit $type only when the runtime type differs from the declared type.
Never 2 Never emit the $type discriminator.