© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•7mo ago•
4 replies
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
TaxComplianceDetails
. If I deserialize in my controller, in an endpoint method, one of the properties of this object,
TaxStatus
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; }
}
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;
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);
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
details
and
taxComplianceDetails 
taxComplianceDetails 
, and in
taxComplianceDetails
taxComplianceDetails
, the
TaxStatus 
TaxStatus 
property is null.

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

where my repo's project has no direct references to NewtonSoft at all.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Newtonsoft.Json deserialize issue [Answered]
C#CC# / help
4y ago
Force Newtonsoft to deserialize into certain formats
C#CC# / help
16mo ago
How to deserialize dictionary using Newtonsoft [Answered]
C#CC# / help
4y ago
Best way to deserialize duplicate JSON API responses (Using Newtonsoft.JSON)
C#CC# / help
16mo ago