Based on certain conditions I need to deserialize JSON strings into different models, sometimes model A, sometimes model B. However in the model A there are JsonPropertyName
attributes from System.Text.Json.Serialization
while in class B there are JsonProperty
attributes from Newtonsoft.Json
. The issue is that the JSON strings correspond to the actual property names and not to the names given in the attributes. I would like to make the JSON serializer, either Newtonsoft or System.Text to ignore its own attributes. It that possible?
That's an example JSON string:
{
"PropertyOne" : "some value"
}
And here is an example model:
public class A
{
[JsonProperty("property_one")]
public string PropertyOne{ get; set; }
}
public class B
{
[JsonPropertyName("property_one")]
public string PropertyOne{ get; set; }
}
PS I can't change the models