I have an entity class with JsonProperty attribute as follows:
public class Book
{
[JsonProperty("id")]
public long BookId { get; set; }
[JsonProperty("name")]
public string BookName { get; set; }
}
I want to deserialize this from JSON string to the entity. Due to JsonProperty id
& name
, the json should have the id/name schema and in that case the deserialize works perfectly (as expected). But in some cases, the json string can also have BookId
and BookName
. Can I have multiple JsonProperty attributes to handle this? Or is there a way to let the serializer know, that if not id then deserialize using BookId? Or any other way to handle this use case?