You are not logged in.
Pages: 1
my custom record is:
TIndicatorExport = record
Index : Integer;
Value : Int64;
// s : string; <================= this field changes the behavior
end;
custom writer is:
class procedure TIndicatorExportCustomWriter.CustomWriter(const aWriter: SynCommons.TTextWriter; const aValue);
var
V: TIndicatorExport absolute aValue;
begin
aWriter.AddJSONEscape(['I', V.Index, 'V', V.Value]);
end;
I register my custom writer by:
SynCommons.TTextWriter.RegisterCustomJSONSerializer(TypeInfo(TIndicatorExport),
nil,
TIndicatorExportCustomWriter.CustomWriter);
And I try use of it:
DynArray: TDynArray;
Data: TArray<TIndicatorExport>;
[..]
DynArray.Init(TypeInfo(TArray<TIndicatorExport>), Data);
Str := DynArray.SaveToJSON(False);
after executed last line the Str has '["00000000000000010000000000000000"]' string,
not my customized, because my custom writer is not called.
BUT... when I add additional field (string) to record then custom serialization works properly!
Where is my mistake?
Last edited by jaclas (2019-06-12 14:51:30)
Offline
It is a compiler limitation, not a framework bug: a record without any managed type doesn't have enough RTTI, IIRC.
One way of bypassing it is to register the dynamic array type, not the record type, for serialization.
Something like that:
type
TIndicatorExports = array of TIndicatorExport;
...
SynCommons.TTextWriter.RegisterCustomJSONSerializer(TypeInfo(TIndicatorExports), nil, TIndicatorExportCustomWriter.CustomWriter);
Online
Pages: 1