Delphi Datasnap - How to customize JSON marshalling -


in delphi 10.1 berlin datasnap rest application, need customize json serializaton of object.

i find solution makes use of jsonreflect attribute, , doesn't involve creation of converters , reverters every specific field, described in this article daniele teti.

in particular, i'm trying serialize object contains:

  • a binary file, convert in json representation - byte array
  • some tdatetime fields, convert in string iso format

i have found technical pdf document marco cantù, talks jsonreflect attribute enable conversion of fields, cannot find documentation it.

anyone can me, please?

use of jsonreflect attribute automatically implies use of converters , reverters. delphi xe6 ships sample project marshallunmarshall json serialization covered. rad studio demo code available online.

if want serialize object contains tdatetime field in string iso format, can use standard tjson class defined in rest.json unit. contains objecttojsonstring method. in aoptions parameter can specify format dates using iso standard.

class function objecttojsonstring(aobject: tobject; aoptions: tjsonoptions = [jodateisutc, jodateformatiso8601]): string; 

to serialize binary file in json daniele teti has sample code in delphi cookbook. unfortunately can not share sample code think. recommended reading! second edition has appeared.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -