#1 2024-08-07 12:20:36

ertank
Member
Registered: 2016-03-16
Posts: 166

Cannot switch RegisterCustomJSONSerializerFromText to mORMot2

Hello,

I have old code that I am converting to use mORMot2 and I have quite a lot code like below

const
  __TTransaction = 'TxnId Int64 TxnTypeId Int64';

...

initialization
  TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TIngenicoResult),                __TTransaction).Options                := [soReadIgnoreUnknownFields];

I could not figure how I can put this so it will work the same as before.

Any help is appreciated.

Thanks & Regards,
Ertan

Offline

#2 2024-08-07 14:35:21

danielkuettner
Member
From: Germany
Registered: 2014-08-06
Posts: 341

Re: Cannot switch RegisterCustomJSONSerializerFromText to mORMot2

perhaps this info in mormot.core.text.pas can help:

// - note: mORMot 1.18 TTextWriter.RegisterCustomJSONSerializerFromText()
  // are moved into Rtti.RegisterFromText() as other similar methods

P.S.
We also have contact with Ingenico

Last edited by danielkuettner (2024-08-07 14:36:20)

Offline

#3 2024-08-07 15:22:40

ertank
Member
Registered: 2016-03-16
Posts: 166

Re: Cannot switch RegisterCustomJSONSerializerFromText to mORMot2

Thank you. In file search returns so many results and repeated filenames that it seems I missed that note.

So, how can I tell mORMot2 to read ignore unknown fields?

Offline

#4 2024-08-07 17:04:32

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

Re: Cannot switch RegisterCustomJSONSerializerFromText to mORMot2

In mORMot 2, ignoring fields is part of the serialization call, not part of the RTTI registration.
As it should.

Offline

#5 2024-08-07 17:46:15

ertank
Member
Registered: 2016-03-16
Posts: 166

Re: Cannot switch RegisterCustomJSONSerializerFromText to mORMot2

I couldn't understand what I read from the document so I did some tests.

Base information

type
  TTransaction = packed record
    TxnId: Int64;
    TxnTypeId: Int64;
  end;

const
  __TTransaction = 'TxnId Int64 TxnTypeId Int64';
var 
  Json: string = '{"test":"additional field","TxnId":1,"TxnTypeId":2}';

...

initialization
  Rtti.RegisterFromText(TypeInfo(TTransaction), __TTransaction);

Tests I did are as follows:

  // Test1 - no dialog displayed
  if mormot.core.json.RecordLoadJson(Test, Json, TypeInfo(TTransaction), nil, False) then
    ShowMessage('OK');

  // Test2 - displays OK dialog
  if mormot.core.json.RecordLoadJson(Test, Json, TypeInfo(TTransaction)) then
    ShowMessage('OK');

Test2 is what I currently have in my unit using Synopse.pas.

It seems I don't need any additional code change as "Tolerant = true" as default and that is what I needed.

Thanks & Regards,
Ertan

Offline

Board footer

Powered by FluxBB