I have this class, as a cut down version:
public class SportTableRow
{
public Int32 Won { get; set; }
public Int32 Lost { get; set; }
public Int32 Drawn { get; set; }
public Int32 For { get; set; }
}
When I make a call to the Data via the WebAPI, it looks like this (again cut down)...
public List<SportTableRow> Get()
{
var options = ....
var sport = ....
var locationCode = ...
return SportManager.GetOverallTable(sport, options,
locationCode).TableRows;
}
When I inspect the returned data in debugger, you can see the properties in the list...
But, when I call via fiddler, you can see that a few properties are missing...
...and it seems to be any Int
's that are 0, and bool
's which are false etc.
Do I need to set anything on the actual class, or something in the JSON serializer?
The JSON serializer JSON.NET is set by default to exclude properties that are set to default values. For Example, boolean=false
, int=0
, int?=null
, object=null
, etc. will be excluded from the resulting JSON. The intention is to minimize bandwidth.
You can change this behavior by changing the settings:
System.Web.Http
.GlobalConfiguration.Configuration
.Formatters
.JsonFormatter
.SerializerSettings
.DefaultValueHandling
= Newtonsoft.Json.DefaultValueHandling.Include;
Best add this line in the Global.asax
file. But note: This will just add bandwidth with no real benefit, especially if you control the client side too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With