www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - vibe.d Serialize/Deserialize SumType to/from json

reply Antonio <antonio abrevia.net> writes:
D offers `SumType` struct to manage tagged Union types.

But there is no support for managing it's Json 
serialization/deserialization (using vibe.d)

Is it a way to add `fromRepresentation` and `toRepresentation` to 
`SumType` (or a way for creating a custom struct "inheriting" 
SumType with serialization capabilities)?

Thank you for advanced.
Jul 04 2022
parent Paul Backus <snarwin gmail.com> writes:
On Monday, 4 July 2022 at 11:35:24 UTC, Antonio wrote:
 (or a way for creating a custom struct "inheriting" SumType 
 with serialization capabilities)?
You can "inherit" from a struct using `alias this`: ```d struct CustomStruct { SumType!(A, B, C) unwrap; alias unwrap this; // serialization stuff here } ``` Documentation: https://dlang.org/spec/class.html#alias-this
Jul 04 2022