Is there recommended way to deserialize with serde without hardcoding the type annotation?


I basically will be receiving serialized data to a bunch of different types, and to be able to reuse code logic, and reduce boilerplate, I would like to avoid hardcoding all the types.

What i need is to be able to pass the deserialized object into a function that takes a concrete type. I will know the type of the serialized data as a string, or I could also know it as a TypeId.

So how can serde produce the concrete type I need, or something on which I can call .into()?

I have been searching for a while, and can’t really find much on the subject, even though I would have thought many people would want to do this.



Actually, I could also take a Box<ConcreteType> as method parameter, which should make things more realistic :wink: