You are not logged in.
I'm getting an exception when trying to serialize a record with an extended type to JSON:
type
TMyRecord = packed record
Value: Extended;
end;
var
MyRec: TMyRecord;
json: RawUTF8;
begin
MyRec.Value := 12.34;
json := RecordSaveJSON(MyRec, TypeInfo(TMyRecord));
end.
Exception: TJSONCustomParserRTTI.CreateFromRTTI("EXTENDED")
This occurs in SynCommons.pas in class function TJSONCustomParserRTTI.CreateFromRTTI():
class function TJSONCustomParserRTTI.CreateFromRTTI(
const PropertyName: RawUTF8; Info: pointer; ItemSize: integer): TJSONCustomParserRTTI;
var Item: PDynArrayTypeInfo absolute Info;
ItemType: TJSONCustomParserRTTIType;
ItemTypeName: RawUTF8;
ndx: integer;
begin
if Item=nil then // no RTTI -> stored as hexa string
result := TJSONCustomParserCustomSimple.CreateFixedArray(PropertyName,ItemSize) else begin
ItemType := TypeNameToSimpleRTTIType(PUTF8Char(@Item.NameLen)+1,Item.NameLen,ItemTypeName);
if ItemType=ptCustom then
ItemType := TypeInfoToSimpleRTTIType(Info,ItemSize);
if ItemType=ptCustom then
if Item^.kind in [tkEnumeration,tkArray,tkDynArray] then
result := TJSONCustomParserCustomSimple.Create(
PropertyName,ItemTypeName,Item) else begin
ndx := GlobalJSONCustomParsers.RecordSearch(Item);
if ndx<0 then
ndx := GlobalJSONCustomParsers.RecordSearch(ItemTypeName);
if ndx<0 then
raise ESynException.CreateUTF8('%.CreateFromRTTI("%")', <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
[self,ItemTypeName]);
result := TJSONCustomParserCustomRecord.Create(PropertyName,ndx);
end else
result := TJSONCustomParserRTTI.Create(PropertyName,ItemType);
end;
if ItemSize<>0 then
result.fDataSize := ItemSize;
end;
We need the extended precision, because the number stored in the database has a precision that requires the extended type: SQL Server: decimal(21, 10)
Thanks!
Offline
Please try http://synopse.info/fossil/info/a0bc6fe136
I've included extended support for record JSON serialization.
But not fully tested yet.
Feedback is welcome!
Offline
Thanks!
Offline