Summary

AliasAttribute can be used to change the field, property or type name, which will be used while serialization and de-serialization. It can be applied to a type itself or a member of class/record.

Syntax

AliasAttribute = class(TAliasBaseAttr);

Remarks

Type names, which can be changed by AliasAttribute, are used while serializing in following cases:

  • To replace field or property name while serializing record or object members.
  • As a runtime type name of object values, if this type differ from field or property compile-time type. This happens when the value of  object field or property is actually a descendant of field/property class type. In this case, serializer have to write run-time object type to be able to restore object while de-serializing. See also NG.Serialization.DefClassAttribute.
To change the name of array elements, NG.Serialization.ElemAliasAttribute  can be used.

Examples

DelphiCopyCode imageCopy Code
type
  [Alias('customer')]
  TMyCustomer = class
  public
    property Name: string;
    [Alias('first-address-line')]
    property Address: string;
    [Alias('second-address-line')]
    property Address2: string;
  end;