I have a problem when deserializing JSON with a string property value of "0". It gets deserialized to null.
{
"name":"Some name",
"isConfigProperty":true,
"displayProperty":false,
"default":"0"
}
This is my class to deserialize to:
public class PropertyModel
{
public string Name { get; set; }
public bool IsConfigProperty { get; set; }
public bool DisplayProperty { get; set; }
public string Default { get; set; }
}
When I change Default value from "0" to "1" or any other number/value it deserializes as it should. But when I change it to "0", I get null again.
Does anyone know about this? Is it possibly a bug in NewtonsoftJson or am I missing something?
Thank you.
System.Text.Jsoneither, see dotnetfiddle.net/VaQU3M. (System.Text.Jsondoes require settingPropertyNameCaseInsensitive = truesince the JSON is camel cased and the model is pascal cased.)JsonConverter<string>inJsonSerializerSettings.Convertersthat is modifying the string value. See How to set json serializer settings in asp.net core 3? to see how a global converter might be getting set, then check your code base to see if this is happening. Or you might have some custom contract resolver inJsonSerializerSettings.ContractResolverthat is applying special logic for properties namedDefault.