Suppose I have an object similar to this:
public class MyObject
{
[JsonProperty(Required = Required.Always)]
public string Prop1 { get; set; }
[JsonProperty(Required = Required.Always)]
public string Prop2 { get; set; }
}
Now, if I try to deserialize a string using JsonConvert, an exception is thrown if any of the properties is missing. However, if I pass an empty string as follows:
JsonConvert.DeserializeObject<MyObject>("")
nullreturns, but no exception is thrown. How to set up MyObjector deserializer so that a JsonExceptionappears just as if there were no required properties?
source
share