CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.
MIT License
2.1k stars 175 forks source link

Disable DefaultValueHandling = DefaultValueHandling.Ignore on the default Json negotiator #155

Closed JoeStead closed 5 years ago

JoeStead commented 5 years ago

By setting DefaultValueHandling = DefaultValueHandling.Ignore on the default json, information is easily left off of the response. Consider the following object:

public class MyObject 
{
 public string Name {get; set;}
 public int CoolRating {get; set; }
}

when it is used:

new MyObject {
Name = Jon,
CoolRating = 0
}

will result in a json object looking like

{
"name": "Jon",
}

where it should actually include the rating field:

{
"name": "Jon",
"CoolRating": 0
}