You are not logged in.
Pages: 1
Hi,
I've recently upgraded to newest Synopse (2016-06-30e55c874993) and noticed a problem with serialization. On old version (1f0ccd0924 from 2013) it was possible to register serialization callback for any object like that:
TJSONSerializer.RegisterCustomSerializer(TObject, TSerializer.ObjectReader, TSerializer.ObjectWriter);
Now it won't work because of change in function JSONObject() in mORMot.pas which now works only for exact types ignoring inheritance. I think it was intentional change but maybe there is still hope to change it. I have around 160 types of objects that I want to serialize and it's troublesome to register them all by hand.
instead of:
if aClassType<>nil then begin
aCustomIndex := JSONCustomParsersIndex(aClassType,aExpectedReadWriteTypes);
if aCustomIndex>=0 then begin
result := oCustom; // found exact custom type (ignore inherited)
exit;
end;
repeat // guess class type (faster than multiple InheritsFrom calls)
i := PtrUIntScanIndex(@TYP,MAX+1,PtrUInt(aClassType));
there should be:
if aClassType<>nil then begin
repeat // guess class type (faster than multiple InheritsFrom calls)
aCustomIndex := JSONCustomParsersIndex(aClassType,aExpectedReadWriteTypes);
if aCustomIndex>=0 then begin
result := oCustom;
exit;
end;
i := PtrUIntScanIndex(@TYP,MAX+1,PtrUInt(aClassType));
If you prefer patch file format here it is:
45851,45855d45850
< aCustomIndex := JSONCustomParsersIndex(aClassType,aExpectedReadWriteTypes);
< if aCustomIndex>=0 then begin
< result := oCustom; // found exact custom type (ignore inherited)
< exit;
< end;
45856a45852,45856
> aCustomIndex := JSONCustomParsersIndex(aClassType,aExpectedReadWriteTypes);
> if aCustomIndex>=0 then begin
> result := oCustom;
> exit;
> end;
Regards,
dc
Offline
Can I count on a response? This patch is important for me to stay in sync with current mORMot sources.
Regards,
dc
Offline
It makes sense. I'm register all my object by hand before (not so match as @dc).
@AB - I check the patch - all regression test are passed, so I commit it. See [eb997028d8]
Last edited by mpv (2016-07-11 10:06:01)
Offline
Thank you for committing this patch. There is another thing that bothers me though. Since this patch makes code compatible with old releases (from year 2013) and change in behavior wasn't discovered by current tests it clearly means there is no test for registering custom serializations. Maybe it's time to add one, just to make long term support easier?
dc
Offline
Pages: 1