You are not logged in.
Pages: 1
Right now I have a service that receives a custom object.
IMyService = interface(IInvokable)
['{E3186F91-F373-48A6-AE92-8931437D4AAF}']
function MyMethod(const ClientId: RawUTF8; const MyClass: TMyClass): TCQRSResult;
end;TMyClass contains a TObjectList<TAnotherObject>. What is the proper, transparent way to handle this? Register a custom deserialization? I cannot use the "ClassName" hack because I don't control the requests being sent to this service, and I find the custom collections method really cumbersome.
Offline
The easiest way is to use a T*ObjArray.
1. define
type
TAnotherObjArray = array of TAnother;2. call in the initialization section of the unit:
initialization
TJSONSerializer.RegisterObjArrayForJSON(TypeInfo(TAnotherObjArray), TAnother);
end.Then you can use TAnotherObjArray as parameter, and you will have the proper serialization.
And no need to release the array: the framework will do it for you.
Also check the ObjArray*() methods to work with this TAnotherObjArray handler.
Offline
Okay - so no TObjectList but instead use Delphi arrays. Got it.
Offline
Note that on mORMot2, RegisterObjArrayForJSon() is needed only for Delphi 7-2009.
FPC and Delphi 2010 are able to recognize the "array of TSomeClass" RTTI and find the correlation between types.
One benefit of the big rewrite of RTTI cache in mORMot2. ![]()
Offline
Pages: 1