serde-rs / json

Strongly typed JSON library for Rust
Apache License 2.0
4.7k stars 536 forks source link

Implement `Deserializer` for `Map<String, Value>` and `&Map<String, Value>` #1134

Open swlynch99 opened 2 months ago

swlynch99 commented 2 months ago

Sometimes I want to work with a Value that I know to be a json object. Map<String, Value> is the correct type to use for this but it is not possible to deserialize from a Map<String, Value> to a more concrete without going through Value. It would be nice if Map<String, Value> implemented Deserializer so this all just works.

My actual use case is that I have a &Map<String, Value> that I would like to deserialize to a concrete struct, which is harder to come up with a workaround for. With an owned value I could just do T::deserialize(Value::Object(map)) but that doesn't work for a reference.