digitalmars.D.learn - How to customize vibe.data.json
- kerdemdemir (27/27) Mar 30 2018 Hi,
- Seb (4/9) Mar 30 2018 I think you are looking for this -
- kerdemdemir (2/13) Mar 30 2018 Exactly :)
- kerdemdemir (30/41) Mar 30 2018 struct RESTTime {
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
Mar 30 2018
On Friday, 30 March 2018 at 16:47:52 UTC, kerdemdemir wrote:Hi, In vibe's web page(http://vibed.org/api/vibe.data.json/serializeToJson) it is told that I should implement [...]I think you are looking for this - https://github.com/vibe-d/vibe.d/pull/2088 Feel free to ping the people there ;-)
Mar 30 2018
On Friday, 30 March 2018 at 17:58:23 UTC, Seb wrote:On Friday, 30 March 2018 at 16:47:52 UTC, kerdemdemir wrote:Exactly :)Hi, In vibe's web page(http://vibed.org/api/vibe.data.json/serializeToJson) it is told that I should implement [...]I think you are looking for this - https://github.com/vibe-d/vibe.d/pull/2088 Feel free to ping the people there ;-)
Mar 30 2018
On Friday, 30 March 2018 at 17:58:23 UTC, Seb wrote:On Friday, 30 March 2018 at 16:47:52 UTC, kerdemdemir wrote:struct RESTTime { SysTime time; alias time this; static RESTTime fromString(string v) { return RESTTime(SysTime.fromSimpleString(v)); } string toString() const { return time.toSimpleString(); } } struct TradeData { UUID sellOrderID; UUID buyOrderID; SysTime buyOrderTime; SysTime sellOrderTime; } void main() { TradeData t; Json jsonResult = t.serializeToJson(); writeln(jsonResult.toString()); } Unfortunately what is shown in the forum is not working with SysTime. My program is being terminated in std.datetime.SysTime.toISOExtString() function by code -11. I hope it does not sound like spoon feeding but do you know any solution for SysTime. I am working on it in parallel. ErdemHi, In vibe's web page(http://vibed.org/api/vibe.data.json/serializeToJson) it is told that I should implement [...]I think you are looking for this - https://github.com/vibe-d/vibe.d/pull/2088 Feel free to ping the people there ;-)
Mar 30 2018









kerdemdemir <kerdemdemir gmail.com> 