www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Deserialize json on runtime type with vibed

reply boolangery <eliott.dumeix gmail.com> writes:
Hi,

I want to do something like that:

The user first register some type associated to a string and a 
callback

registerHandler!Foo("foo", (res) {
   info("message received");
});


I want the callback to be called when a json packet containing 
the string "foo" arrives on a transport layer. Then the full json 
message is deserialized to Foo class using deserializeJson!

The type is known at runtime, so how can I use deserializeJson 
with a runtime type ?

Thanks in advance
May 12 2018
parent Stefan Koch <uplink.coder googlemail.com> writes:
On Saturday, 12 May 2018 at 20:23:27 UTC, boolangery wrote:
 Hi,

 I want to do something like that:

 The user first register some type associated to a string and a 
 callback

 registerHandler!Foo("foo", (res) {
   info("message received");
 });


 I want the callback to be called when a json packet containing 
 the string "foo" arrives on a transport layer. Then the full 
 json message is deserialized to Foo class using deserializeJson!

 The type is known at runtime, so how can I use deserializeJson 
 with a runtime type ?

 Thanks in advance
via exposing a virtual method which instantiates the template.
May 13 2018