The unit provides some helper classes to make serializing classes into JSON a bit easier.
The JsonUTCDate attribute applied to ca field results in the field value being converted into UTC format when serialized into JSON format. Of course the conversion is reverted when the field is set from JSON. If the field value equals cNoDate (i.e. "0000-00-00T00:00:00.000Z") conversion from/into local time format is skipped. When writing such a value it will result in a JSON null object value.
type TMyClass = class private [JsonUTCDate] FStartDate: TDateTime; [JsonUTCDate] FEndDate: TDateTime; ... end;
The JsonStrings attribute applied to a TStrings or descendant will serialize the strings to an array of string and vice versa. Note that it should always be accompanied by JSONOwned(False).
type TMyClass = class private [JSONOwned(False), JSONStrings] FLines: TStringList; ... end;
JsonObjectList is an attribute that should be applied to a TObjectList instance or descendant. It makes the object being serialized to an array of object and back again. It needs an interceptor class derived from TObjectListInterceptor as parameter. It also requires a JSONOwned(False) companion.
type TContactList = TIdentList<TContact>; TContactListInterceptor = TObjectListInterceptor<TContact>; type TMyAddressBook = class private [JSONOwned(False), JsonObjectList(TContactListInterceptor)] FContacts: TContactList; ...
The alias TContactList is actually not needed, but the TContactListInterceptor is mandatory - as well as at least one type keyword between the alias declaration and the use of the alias inside the attribute.