json icon indicating copy to clipboard operation
json copied to clipboard

Add a `from_value_ref` function to deserialize structs with `#[serde(borrow)]`

Open SamWilsn opened this issue 3 years ago • 0 comments

I'm not 100% sure such an idea would work, but here's the problem I'm having:

#[derive(Deserialize)]
struct Foo<'a> {
    #[serde(borrow)]
    inner: &'a str,
}

If I want to deserialize such a struct, and the JSON contains escaped characters, serde_json can't replace the escape sequences with the correct characters.

What if I first deserialized to a serde_json::Value, then deserialized from that to my target struct?

SamWilsn avatar Aug 19 '22 15:08 SamWilsn