You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to use a std.typecons.Typedef in my code. Or Quantity from experimental.units. That kind of thing.
These are structs defined outside my own code. How do I serialize them to JSON? Well, if I'm only using them in a couple places, I can provide serialization properties, eg:
If I use it everywhere, I can write a wrapper struct:
structQuant(alias unitValue) {
typeof(unitValue) val;
alias val this;
@jsonize {
doublevalue() { return val.toValue; }
voidvalue(double newVal) { val = unitValue * newVal; }
}
}
// now replace Quantity!Metre with Quant!metre etc
It would be nicer to inject into jsonizer a means of deserializing Quantity and other externally defined types. (Adding a convertToJSON method accessible at the JsonizeMe mixin site doesn't work.)
The text was updated successfully, but these errors were encountered:
I want to use a std.typecons.Typedef in my code. Or Quantity from experimental.units. That kind of thing.
These are structs defined outside my own code. How do I serialize them to JSON? Well, if I'm only using them in a couple places, I can provide serialization properties, eg:
If I use it everywhere, I can write a wrapper struct:
It would be nicer to inject into jsonizer a means of deserializing Quantity and other externally defined types. (Adding a
convertToJSON
method accessible at theJsonizeMe
mixin site doesn't work.)The text was updated successfully, but these errors were encountered: