I'm getting some JSON data from the external API. I have my POCO objects to which the data is deserialized. I use System.Text.Json.JsonSerializer for deserialization. Recently, I realized that the structure of the JSON that I receive has changed and I got to know it only by accident while checking something else. My question is, is it possible to catch somehow the json data that didn't succeed to be mapped to any POCO fields?
To be more precise with my question here is an example POCO:
public class Car
{
public string Name { get; set; }
public int Age { get; set; }
}
JSON that I received before:
{"Name" : "PinkCar", "Age": 3}
JSON that I receive now:
{"Name" : "PinkCar", "Age": 3, "RogueField": "Loser"}
I would like to be able to at least get somehow information that there is this new "RogueField" that doesn't match any POCO properties without breaking the process of deserialization.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…