Skip to content

Commit 78f1bec

Browse files
committed
Yaml improvements
1 parent 4ce15f2 commit 78f1bec

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

Quick.YAML.Serializer.pas

+38-29
Original file line numberDiff line numberDiff line change
@@ -192,43 +192,52 @@ function TRTTIYaml.DeserializeDynArray(aTypeInfo: PTypeInfo; aObject: TObject; c
192192
TValue.Make(@pArr,aTypeInfo, Result);
193193
rDynArray := ctx.GetType(Result.TypeInfo) as TRTTIDynamicArrayType;
194194

195-
for i := 0 to aYamlArray.Count - 1 do
196-
begin
197-
rItemValue := nil;
198-
case rType.Kind of
199-
tkClass :
200-
begin
201-
if TYamlPair(aYamlArray.Items[i]).Value is TYamlObject then
195+
try
196+
for i := 0 to aYamlArray.Count - 1 do
197+
begin
198+
rItemValue := nil;
199+
case rType.Kind of
200+
tkClass :
202201
begin
203-
Yaml := TYamlObject(TYamlPair(aYamlArray.Items[i]).value);
204-
propObj := GetValue(PPByte(Result.GetReferenceToRawData)^ +rDynArray.ElementType.TypeSize * i, rDynArray.ElementType).AsObject;
205-
if propObj = nil then
206-
begin
207-
objClass := rType.TypeData.ClassType;
208-
rItemValue := DeserializeClass(objClass,yaml);
209-
end
210-
else
202+
if aYamlArray.Items[i] = nil then raise Exception.Create('Value empty!');
203+
204+
if TYamlPair(aYamlArray.Items[i]).Value is TYamlObject then
211205
begin
212-
DeserializeObject(propObj,yaml);
206+
Yaml := TYamlObject(TYamlPair(aYamlArray.Items[i]).value);
207+
propObj := GetValue(PPByte(Result.GetReferenceToRawData)^ +rDynArray.ElementType.TypeSize * i, rDynArray.ElementType).AsObject;
208+
if propObj = nil then
209+
begin
210+
objClass := rType.TypeData.ClassType;
211+
rItemValue := DeserializeClass(objClass,yaml);
212+
end
213+
else
214+
begin
215+
DeserializeObject(propObj,yaml);
216+
end;
213217
end;
214218
end;
215-
end;
216-
tkRecord :
219+
tkRecord :
220+
begin
221+
Yaml := TYamlObject(TYamlPair(aYamlArray.Items[i]).value);
222+
rItemValue := DeserializeRecord(GetValue(PPByte(Result.GetReferenceToRawData)^ +rDynArray.ElementType.TypeSize * i,
223+
rDynArray.ElementType),aObject,Yaml);
224+
end;
225+
tkMethod, tkPointer, tkClassRef ,tkInterface, tkProcedure :
226+
begin
227+
//skip these properties
228+
end
229+
else
217230
begin
218-
Yaml := TYamlObject(TYamlPair(aYamlArray.Items[i]).value);
219-
rItemValue := DeserializeRecord(GetValue(PPByte(Result.GetReferenceToRawData)^ +rDynArray.ElementType.TypeSize * i,
220-
rDynArray.ElementType),aObject,Yaml);
231+
rItemValue := DeserializeType(aObject,rType.Kind,rType,aYamlArray.Items[i].Value);
221232
end;
222-
tkMethod, tkPointer, tkClassRef ,tkInterface, tkProcedure :
223-
begin
224-
//skip these properties
225-
end
226-
else
227-
begin
228-
rItemValue := DeserializeType(aObject,rType.Kind,rType,aYamlArray.Items[i].Value);
229233
end;
234+
if not rItemValue.IsEmpty then Result.SetArrayElement(i,rItemValue);
235+
end;
236+
except
237+
on E : Exception do
238+
begin
239+
raise Exception.CreateFmt('Array %s item %d error (%s)',[rtype.Name, i, e.Message]);
230240
end;
231-
if not rItemValue.IsEmpty then Result.SetArrayElement(i,rItemValue);
232241
end;
233242
//aProperty.SetValue(aObject,rValue);
234243
finally

0 commit comments

Comments
 (0)