Deserializing JSON as an abstract type
Heromyth
bitworld at qq.com
Tue Nov 19 00:57:59 UTC 2019
On Tuesday, 19 November 2019 at 00:40:16 UTC, Chris wrote:
> So I'm trying to make a D wrapper for Telegram's JSON API using
> libtdjson. All results coming from the JSON API take the
> following structure:
>
> {
> "@type": "className",
> "foo": "bar",
> "baz" {
> "@type": "otherClass"
> }
> }
>
> where every object, including nested ones, has a "@type" field
> which will correspond to a D class. There will be over 770
> possible types. So what I'm trying to figure out is how to
> deserialize the JSON so that it automatically gets parsed into
> the correct type.
>
> I'm looking at asdf right now, but it doesn't seem like it has
> anything like that built in. Any ideas?
Can you have a look at this :
https://github.com/huntlabs/hunt/blob/master/examples/UnitTest/source/test/JsonSerializerTest.d
The JsonSerializer can serialize and deserialize a complex class.
More information about the Digitalmars-d-learn
mailing list