{ TDateTimeConverter } function TDateTimeConverter.CanConvert(ATypeInf: PTypeInfo): Boolean; begin Result := True; end; function TDateTimeConverter.ReadJson(const AReader: TJsonReader; ATypeInf: PTypeInfo; const AExistingValue: TValue; const ASerializer: TJsonSerializer): TValue; begin var tempDT: TDateTime; var strValue := AReader.Value.AsString.Replace('-', '/'); if TryStrToDateTime(strValue, tempDT) then Result := tempDT else Result := TValue.Empty; end; procedure TDateTimeConverter.WriteJson(const AWriter: TJsonWriter; const AValue: TValue; const ASerializer: TJsonSerializer); begin AWriter.WriteValue(AValue); end;
TTestRec = record
[JsonConverter(TDateTimeConverter)]
DT: TDateTime;
end;