Hi.
I'm trying to parse a JSON that looks like this:
{
"itemId": "some-id",
"title": "redacted",
"leafCategoryIds": [
"0000000"
],
"categories": [
{
"categoryId": "000000",
"categoryName": "redacted"
}
],
"image": {
"imageUrl": "redacted"
}
}
I have these structures:
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct SearchItem {
#[serde(rename = "itemId")]
id: String,
title: String,
// leafCategoryIds - dont care
categories: Vec<Category>,
image: Image,
}
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Image {
#[serde(rename = "imageUrl")]
url: String,
}
Is there any way to parse the image
key without having to create a wrapper struct (Image
) just because of a single key? I only need the imageUrl
. So for example the SearchItem
structure would look something like this:
#[derive(Debug, Clone, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct SearchItemSimplified {
#[serde(rename = "itemId")]
id: String,
title: String,
// leafCategoryIds
categories: Vec<Category>,
// image->imageUrl
image: String,
}