How to customize vibe.data.json

kerdemdemir kerdemdemir at gmail.com
Fri Mar 30 16:47:52 UTC 2018


Hi,

In vibe's web 
page(http://vibed.org/api/vibe.data.json/serializeToJson) it is 
told that I should implement

Json toJson() const;
static T fromJson(Json src);

string toString() const;
static T fromString(string src);

I think I should implement those as member functions(I am not 
sure).

I have a struct like:

struct TradeData
{
	import std.uuid : UUID;
	import std.datetime : SysTime;

	UUID   sellOrderID;
	UUID   buyOrderID;
	SysTime buyOrderTime;
	SysTime sellOrderTime;	
}

What I want is automatically json conversion of UUID and SysTime 
classes by returning UUID.toString() and SysTime.toSimpleString() 
methods when serializeToJson() is being called. Since these are 
std classes I don't know how can I manipulate them.

Can you please tell me how should I use toJson(), fromJson() 
functions for customizing user defined objects.

Erdem



More information about the Digitalmars-d-learn mailing list