#1 2017-12-11 13:00:14

yankee
Member
Registered: 2015-04-08
Posts: 7

[SOLVED] RecordLoadJSON / DynArrayLoadJSON with reserved words

Hi,
I'm using RecordLoadJSON / DynArrayLoadJSON with custom serialization
(TTextWriter.RegisterCustomJSONSerializerFromText)
and I'm facing a problem with a JSON object like this:

{
  "type": 1,
  "name": "myName"
}

the problem is that I cannot map it to this

type
  TDBRec_myRec = packed record
    type: Integer;    // <-- error! "type" is a reserved keyword
    name: RawUTF8;
  end;
const
  __TDBRec_myRec = 'type: Integer;  name: RawUTF8';

Is there some way to tell the serializer to map JSON "type" to some other record field?

Thank you very much.

Last edited by yankee (2017-12-11 16:09:33)

Offline

#2 2017-12-11 15:41:49

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

Re: [SOLVED] RecordLoadJSON / DynArrayLoadJSON with reserved words

The name in the text definition is not required to map the field name in the record.
So you can write:

type
  TDBRec_myRec = packed record
    atype: Integer; 
    name: RawUTF8;
  end;
const
  __TDBRec_myRec = 'type: Integer;  name: RawUTF8';

Offline

#3 2017-12-11 16:08:25

yankee
Member
Registered: 2015-04-08
Posts: 7

Re: [SOLVED] RecordLoadJSON / DynArrayLoadJSON with reserved words

Thank you!!
I didn't catch that mapping is positional.

Offline

Board footer

Powered by FluxBB