I have two
public class CustomerInformation
{
public int? YearsofPurchase { get; set; }
public int? Age{ get; set; }
}
For some reason during deserialization to this object, when the json corresponding fields are null they are making the above two fields to show zero 0 instead of null.
Can someone point to tips please? Tried removing the two properties from Json when null so that during deserialization it would not have any value and then YearsofPurchase and Age would remain null.. but even then they are converting to 0.
result = JsonConvert.DeserializeObject<CustomerInformation>(response, custDefualtSettings());
Values of my custDeafultsettings:
TypeNameHandling = TypeNameHandling.All,
TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full,
MissingMemberHandling = MissingMemberHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Include,
NullValueHandling = NullValueHandling.Include,
Actual Response:
{
"$id": "1",
"$type": "Customer.CustomerInformation, Customer.Common",
"CustomerId": 103606055,
"YearsofPurchase ": null,
"Age": null,
"PhoneNumber": "",
}
Tried removing the null properties from Json as shown below but still those properties value show as 0 on customerInformation.
{
"$id": "1",
"$type": "Customer.CustomerInformation, Customer.Common",
"CustomerId": 103606055,
"PhoneNumber": "",
}