I need some extra type information on a URL, so I've created a UrlWithPhantomdata
struct with a value field for the URL and a PhantomData
field. How can I deserialize a string into this struct with Serde?
More specifically, given this JSON object:
{
"url": "https://example.com"
}
How can I deserialize it into the following ApiData
struct?
#[derive(Deserialize)]
pub struct ApiData {
url: UrlWithPhantomdata<i32>
}
#[derive(Deserialize)]
pub struct UrlWithPhantomdata<T> {
#[serde(with = "url_serde")]
url_value: Url,
#[serde(skip)]
url_type: PhantomData<T>
}
The more general problem is addressed in serde-rs/serde#1048, but I'm looking for a solution that works until that bug is fixed.