public class Output
{
public string Property { get; set; }
}
string json = "{\"Property\":\"foo\", \"P2\":\"foo\"}";
var output = JsonConvert.DeserializeObject(json, typeof(Output), /*settings?*/); //should throw error "P2" not found in class "Output"
I need to throw error if JSON not exactly maps into class (i.e. not strong typed). In this case "P2" is not present in Output class, and is not valid.
UPDATE:
People mention about duplicate but this is not duplicate. Field is not required it is simply DOES NOT EXIST in output class. Nothing to be marked with required attribute, please, read more carefully next time.