November 19, 2019 Deserializing JSON as an abstract type | ||||
---|---|---|---|---|
| ||||
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? |
November 19, 2019 Re: Deserializing JSON as an abstract type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Chris | 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. |
Copyright © 1999-2021 by the D Language Foundation