serde-rs / json

Strongly typed JSON library for Rust
Apache License 2.0
4.85k stars 555 forks source link

Non-obvious error message when unable to borrow string and there aren't obvious escape sequences #1144

Open skeggse opened 3 months ago

skeggse commented 3 months ago

I'm trying to deserialize an OCI manifest into some structs that have &'a str fields, and serde_json is indicating that it can't do that for some specific values. I can fix the issue by using Cow<'a, str> instead, but I'm kinda curious to understand why this is happening. I can understand why this would happen for escape sequences, but I don't seem to have any escape sequences in my JSON! Are there other reasons this might be happening?

invalid type: string "application/vnd.docker.distribution.manifest.v2+json", expected a borrowed string at line 1 column 165

References:

skeggse commented 3 months ago

Ok I should have looked closer at the input - I guess the AWS ECR API escapes the forward-slashes?

Maybe a realistic issue here is to make the error message a little clearer. I don't suppose there's a way to have it show the source bytes rather than the string after it's been had its escape sequences resolved?