I have two format of JSON which I want to Deserialize to one class.
I know we can't apply two [JsonProperty]
attribute to one property.
Can you please suggest me a way to achieve this?
string json1 = @"
{
'field1': '123456789012345',
'specifications': {
'name1': 'HFE'
}
}";
string json2 = @"
{
'field1': '123456789012345',
'specifications': {
'name2': 'HFE'
}
}";
public class Specifications
{
[JsonProperty("name1")]
public string CodeModel { get; set; }
}
public class ClassToDeserialize
{
[JsonProperty("field1")]
public string Vin { get; set; }
[JsonProperty("specification")]
public Specifications Specifications { get; set; }
}
I want name1
and name2
both to be deserialize to name1
property of specification class.