Jump to content
Sign in to follow this  
microtronx

Need help: Datasnap, Rest, Json and Marshalling

Recommended Posts

Hi, i'm searching now for days how to setup datasnap / json to automatically Marshall and UnMarshall following Object;

 

	__Constants = record
	public
		vname:string;
		vwert:variant;
	end;
	tmyObject = class(tObject)
	private
		[JSONMarshalled(False)]
		fData:tDictionary<string, __Constants>;

		fJsonValue:string;
		fname:string;

		function getJsonValue():string;
		procedure setJsonValue(vValue:string);
		function fData_get(vindex:int64):_Constants;
	public
		constructor Create;
		destructor Destroy; override;

		property  cName:string read fname write fname;
		property  cData[index:int64]:__Constants read fData_get;

		[JSONMarshalled(true)]
		property JsonValue:string read getJsonValue write setJsonValue;
	end;

 

I hoped that the marshaller get's the value of property JsonValue so the getJsonValue() is called and converts the fData to Json but it does not. The Marshaller directly read the fJsonValue which is empty.

Also i can't find any good documentation about the attributes like [JSONMarshalled(false|true)]

 

Any help is appreciated.

Share this post


Link to post
8 minutes ago, Dalija Prasnikar said:

This is design error in built in Delphi JSON library. Instead of working with properties it works with fields. 

 

https://quality.embarcadero.com/browse/RSP-26262

 

AFAIK there are some options to add custom converters , but I never used it... take a look at REST.JsonReflect and Data.DBXJSONReflect

Thanks for link to rsp.

I have read a lot regarding DBXJSONReflect but there is no good documentation so i don't know how to create a custom converter for my object, so that datasnap uses the registered converters for Marshal and UnMarshal.

 

Edited by microtronx
so that datasnap uses the registered converters for Marshal and UnMarshal.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×