Linked Questions
32 questions linked to/from How to set custom JsonSerializerSettings for Json.NET in ASP.NET Web API?
117 votes
9 answers
107k views
Web API 2: how to return JSON with camelCased property names, on objects and their sub-objects
UPDATE Thanks for all the answers. I am on a new project and it looks like I've finally got to the bottom of this: It looks like the following code was in fact to blame: public static ...
110 votes
4 answers
34k views
Keep casing when serializing dictionaries
I have a Web Api project being configured like this: config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); However, I want dictionary ...
44 votes
3 answers
39k views
Web API: Configure JSON serializer settings on action or controller level
Overriding the default JSON serializer settings for web API on application level has been covered in a lot of SO threads. But how can I configure its settings on action level? For example, I might ...
17 votes
3 answers
49k views
JSON Deserialization - String Is Automatically Converted To Int
When I deseiralize the JSON to the C# object below, either using Newtonsoft explicitly or via the model binding mechanism of ASP.NET Web Api, the string id value is automatically converted to int. I ...
15 votes
1 answer
23k views
Json.net deserialization null guid case
I'm deserializing an object using Json.NET that contains a private field of type Guid and a public property for that field. When the value for my Guid is null in my json I want to assign Guid.Empty to ...
11 votes
2 answers
6k views
Is it possible to set Json.Net to ignore $type?
Watching this video on json deserialization attacks and it shows this bit of json that can be used to trigger arbitrary code execution on any application that deserializes it. Now in my applications, ...
4 votes
2 answers
5k views
JsonSerializationException on lazy loaded nHibernate object in WebApi when called from Angularjs service
I am calling a WebApi controller Get method from an Angularjs service. The angular service: app.service('MyService', ['$http', function ($http) { var getMyObjects = function () { var ...
4 votes
2 answers
4k views
Force JObject to serialzie date in "dd-mm-yyyy" format
public Guid AddJobs(JObject parametrs) { dynamic jsonParameters = parametrs; JobViewModel job = jsonParameters.Job.ToObject<JobViewModel>(); } Above is my code. I am trying to ...
1 vote
2 answers
4k views
Json.Net deserialize into C# derived class
Json.Net is not deserializing the object it receives into the proper derivatives of my Control class. (Please see the following explanation of the problem. Also please note, I feel this is the minimum ...
5 votes
1 answer
2k views
Access custom attributes of .NET class inside custom json converter
In my project, I have written a custom json converter to trim the white-spaces present in the string property. Here is an example of the typical class we will use, public class Candidate { ...
2 votes
1 answer
3k views
Parameter values are not mapped in Web API, if the Model class is marked as Serializable
I have a Web Api Controller as shown below public class HomeController : ApiController { .... [HttpPost] [Route("api/Add")] public IHttpActionResult Add(Employee emp) { ......
2 votes
1 answer
3k views
JSON property case sensitivity when binding
When submitting a JSON body to an MVC application I get the following exception during binding: An item with the same key has already been added. This happens when a HTTP body has 2+ JSON properties ...
1 vote
2 answers
3k views
How to return json date from MVC4 controller in ISO format
I tried tro return date in ISO format using Json.Net from ASP.NET MVC4 controller public JsonResult Sales() { var saleList = new List<Sale>(); ... var str = JsonConvert....
2 votes
2 answers
2k views
Deserializing into derived class in ASP.NET Web API
In my last SO question, I asked how to modify the serializer settings for Json.NET, which ASP.NET Web API natively uses for (de)serialization. The accepted answer worked perfectly, and I was, for ...
2 votes
1 answer
1k views
ModelState error - Newtonsoft.Json.JsonSerializationException: Cannot populate list type System.Net.TrackingStringDictionary
I have the error in the title when a try to call webApi. This is my class: public class NotificationDTO { public long idCompanyService { get; set; } public DocTypeEnum DocumentType { get; ...