C#C
C#5mo ago
VoidPointer

NewtonSoft Deserialize Not Working Properly In API Controller

I have a situation where if I deserialize a string in my own repository class, I get the full object, an instance of TaxComplianceDetails. If I deserialize in my controller, in an endpoint method, one of the properties of this object, TaxStatus, is null.

public class TaxComplianceDetails
{
    public string TaxRefNumber { get; set; }
    public Taxstatus TaxStatus { get; set; }
}
public class Taxstatus
{
    public int SuccessInd { get; set; }

    [JsonProperty("ComplianceStatus", NullValueHandling = NullValueHandling.Ignore)]
    public string ComplianceStatus { get; set; }

    [JsonProperty("CreatedOnDt", NullValueHandling = NullValueHandling.Ignore)]
    public DateTime? CreatedOnDt { get; set; }

    [JsonProperty("eFiling", NullValueHandling = NullValueHandling.Ignore)]
    public bool? EFiling { get; set; }
}

My repo uses this code to deserialize:
var returnObject = JsonConvert.DeserializeObject<TaxComplianceDetails>(extraInfo.sars_tax_compliance_details);
return returnObject;


In the controller I have this code:
var db = new SarsDbService();
var details = db.ReadTaxComplianceDetails(kycId, ref logHelper, _session, extraInformation);
taxComplianceDetails = JsonConvert.DeserializeObject<TaxComplianceDetails>(extraInformation.sars_tax_number_details);


On my breakpoint just after the above code, I inspect details and taxComplianceDetails , and in taxComplianceDetails, the TaxStatus property is null.

I somewhat suspect a version mismatch, because the controller has this in the Startup.ConfigureServices method, and the project has this package reference
Microsoft.AspNetCore.Mvc.NewtonsoftJson

where my repo's project has no direct references to NewtonSoft at all.
Was this page helpful?