static void Main(string[] args)
{
const string someSerializedValue = "{\"SomeValue\":true}";
var stringBool = JsonConvert.DeserializeObject<StringBool>(someSerializedValue);
var actualBool = JsonConvert.DeserializeObject<ActualBool>(someSerializedValue);
}
private class StringBool
{
// I want this to fail
public string SomeValue { get; set; }
}
private class ActualBool
{
public bool SomeValue { get; set; }
}
Note that SomeValue
is a boolean true
in JSON. So I'd like the deserialization step to fail for stringBool
. But it doesn't. Is there an attribute that will be more strict about what valid deserialization is in cases like this?