Skip to content

Commit

Permalink
Quick.Json.Serializer improved fpc serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Jan 24, 2019
1 parent 22d99ae commit 8adddd8
Showing 1 changed file with 55 additions and 3 deletions.
58 changes: 55 additions & 3 deletions Quick.Json.Serializer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1154,10 +1154,62 @@ function TRTTIJson.Serialize(const aName : string; aValue : TValue) : TJSONPair;
//Result.JsonString := TJSONString(aName);
try
case avalue.Kind of
tkInteger, tkInt64 :
tkClass :
begin
Result.JsonValue := TJSONValue(Serialize(aValue.AsObject));
end;
tkString, tkLString, tkWString, tkUString :
begin
Result.JsonValue := TJSONString.Create(aValue.AsString);
end;
tkChar, tkWChar :
begin
Result.JsonValue := TJSONString.Create(aValue.AsString);
end;
tkInteger :
begin
Result.JsonValue := TJSONNumber.Create(aValue.AsInteger);
end;
tkInt64 :
begin
Result.JsonValue := TJSONNumber.Create(aValue.AsInt64);
end;
tkFloat :
begin
if aValue.TypeInfo = TypeInfo(TDateTime) then
begin
Result.JsonValue := TJSONString.Create(DateTimeToJsonDate(aValue.AsExtended));
end
else if aValue.TypeInfo = TypeInfo(TDate) then
begin
Result.JsonValue := TJSONString.Create(DateToStr(aValue.AsExtended));
end
else if aValue.TypeInfo = TypeInfo(TTime) then
begin
Result.JsonValue := TJSONString.Create(TimeToStr(aValue.AsExtended));
end
else
begin
Result.JsonValue := TJSONNumber.Create(aValue.AsExtended);
end;
end;
tkEnumeration :
begin
if (aValue.TypeInfo = System.TypeInfo(Boolean)) then
begin
Result.JsonValue := TJSONBool.Create(aValue.AsBoolean);
end
else
begin
//Result.JsonValue := TJSONString.Create(GetEnumName(aValue.TypeInfo,aValue.AsOrdinal));
if fUseEnumNames then Result.JsonValue := TJSONString.Create(aValue.ToString)
else Result.JsonValue := TJSONNumber.Create(GetEnumValue(aValue.TypeInfo,aValue.ToString));
end;
end;
tkSet :
begin
Result.JsonValue := TJSONString.Create(aValue.ToString);
end;
else
begin
//raise EJsonDeserializeError.CreateFmt('Not supported type "%s":%d',[aName,Integer(aValue.Kind)]);
Expand Down Expand Up @@ -1211,10 +1263,10 @@ function TRTTIJson.Serialize(aObject : TObject; aType : TTypeKind; const aProper
end;
end;
end;

Result.JsonValue := jArray;
finally
DynArrayClear(pArr,propinfo.PropType);
//DynArrayClear(pArr,propinfo.PropType);
pArr := nil;
end;
end;
tkClass :
Expand Down

0 comments on commit 8adddd8

Please sign in to comment.