Consider the following 3rd party (Magento) API response where this is one entry in a collection of products:
{
"id":121,
"sku":"008MBLU",
"name":"Pillow Covers - King Mauve (2-pack)",
"custom_attributes":{
"11":{
"attribute_code":"ship_length",
"value":"11.0000"
},
"16":{
"attribute_code":"ship_width",
"value":"7.0000"
},
"19":{
"attribute_code":"ship_height",
"value":"1.0000"
}
}
}
And the desired resulting class to deserialize to:
public class Product
{
[JsonProperty("id")]
public long Id { get; set; }
[JsonProperty("sku")]
public string SKU { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("ship_length")]
public decimal ShipLength { get; set; }
[JsonProperty("ship_width")]
public decimal ShipWidth { get; set; }
[JsonProperty("ship_height")]
public decimal ShipHeight { get; set; }
}
I found this post, which is part way what I need, which would ignore the higher level wrapper of the int
values wrapping each custom_attribute
. But I don't know where to start with regards to having a custom resolver that is for the custom_attribute
property, and then assign it's value to another property....and I'm new to custom resolvers in general.