#1 2016-07-05 10:36:57

dc
Member
Registered: 2012-11-16
Posts: 46

Unable to serialize all objects anymore

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

#2 2016-07-11 08:01:50

dc
Member
Registered: 2012-11-16
Posts: 46

Re: Unable to serialize all objects anymore

Can I count on a response? This patch is important for me to stay in sync with current mORMot sources.

Regards,
dc

Offline

#3 2016-07-11 10:04:31

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,544
Website

Re: Unable to serialize all objects anymore

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

#4 2016-07-11 12:49:10

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,240
Website

Re: Unable to serialize all objects anymore

Patch is just fine!

Offline

#5 2016-07-12 08:24:51

dc
Member
Registered: 2012-11-16
Posts: 46

Re: Unable to serialize all objects anymore

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

Board footer

Powered by FluxBB