very stuck atm, have been in .net core world but back to .net3.5 and struggling.
I have a asmx webservice that I haven't worked on before, it uses jsonserialisation set in the web.config
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647" />
</webServices>
</scripting>
My web methods are like so
[ScriptMethod(ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
[WebMethod]
public SyncDownResponse SyncDown(string syncDownReq)
{
return Wrap<SyncDownSummaryRequest, SyncDownSummaryResponse>(_service.SyncDownSummary, syncDownSummaryRequestObject);
}
What this does it returns a SyncDownResponse object that is serialised by json in the webservice setup. This all works fine.
Now what I want to do is to ignore null values when serialising the data down. I have tried this
public bool ShouldSerializeCompanyParameters()
{
return CompanyParameters.HasValue;
}
And adding the json property attribute
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
But the code is not being hit. If I call JsonConvert.SerializeObject it does call the should serialise method incidently.
Anyway, there must be a way to set the serialisation settings to ignore null values but I'm struggling. I have found articles to set GlobalConfiguration in the Global.asax file but am getting a reference missing for GlobalConfiguration. I have added all the System.Web references but nothing. I suspect that it may not be present in .net3.5. Any help would be great, I guess I could set something in the web.config or the Global.asax but stuck at the moment
Thanks