#1 2021-03-11 23:20:24

Mane
Member
Registered: 2017-02-20
Posts: 15

RegisterCustomJSONSerializerFromText and string literal 255 limit

Hello folks,

Today I hit a wall, and hope some of you guys know a workaround...

I'm registering a bunch of Custom JSON Serializer for a types I need to convert from JSON to TObject using the following statement...

TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TMyClass), 'field1, field2, field3 RawUTF8').Options := [soReadIgnoreUnknownFields];

However, I've exceed the 255 string literal limit of the Delphi compiler for a medium size packed record.

How do you register a Custom JSON Serializer for a type with over 50 fields?

Thanks in advance for you help.

Regards,
Mario

Last edited by Mane (2021-03-11 23:20:56)

Offline

#2 2021-03-12 07:26:23

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

Re: RegisterCustomJSONSerializerFromText and string literal 255 limit

You can use a local variable, I guess.

Offline

#3 2021-03-12 07:50:27

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: RegisterCustomJSONSerializerFromText and string literal 255 limit

ab wrote:

You can use a local variable, I guess.

Or... split the string, it's just a compiler limit

TTextWriter.RegisterCustomJSONSerializerFromText(
TypeInfo(TMyClass), 

'field1, field2, ' + 'field3 RawUTF8'

).Options := [soReadIgnoreUnknownFields];

Offline

#4 2021-03-12 17:21:47

Mane
Member
Registered: 2017-02-20
Posts: 15

Re: RegisterCustomJSONSerializerFromText and string literal 255 limit

sakura wrote:
ab wrote:

You can use a local variable, I guess.

Or... split the string, it's just a compiler limit

TTextWriter.RegisterCustomJSONSerializerFromText(
TypeInfo(TMyClass), 

'field1, field2, ' + 'field3 RawUTF8'

).Options := [soReadIgnoreUnknownFields];

Yes, I've not though about that, thank you!

Regards,
Mane

Offline

Board footer

Powered by FluxBB