#1 2017-01-05 18:30:59

dolfin
Member
Registered: 2015-09-11
Posts: 22

TSQLRecord custom serialization

Hello!

Is there any possibility to perform custom TSQLRecord serialization?

The problem is that I need to map my Model's properties names to different names. For example in my Model I have published property "Name" and as a result I get such a JSON on certain REST server call:  {"Name": "test"}. But I need to have a possibility to change this property name to get something like {"_name": "test"}. I tried to use TJSONSerializer.RegisterCustomSerializer(TMySQLRecord, nil, TMySQLRecord.FVClassWriter); but custom serialization method is not called on REST request. Custom serialization methos is called only on explicity ObjectToJson function call.

Many thanks in advanced!

Offline

#2 2017-01-05 18:50:20

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

Re: TSQLRecord custom serialization

No, TSQLRecord should have direct serialization of published properties, maybe via getter/setter.
JSON serialization is used internally by the ORM, even without any REST remote access.

What you can do is define the table as external, use a SynDBSQLite3 connection, and define a custom mapping.

Another way - which I would fell better - is to define a custom REST service (using a method-based service or an interface-based service) returning the expected data.

Online

Board footer

Powered by FluxBB