I created a custom converter extending from JsonConverter
, which would be used for an ASP.NET MVC and a Web API.
public class MyCustomConverter : JsonConverter
{
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
....
}
}
And I created this CustomObject
that uses that converter:
[JsonConverter(typeof(MyCustomJsonConverter))]
public class CustomObject
{
...
}
This converter work correctly for second application (WebApi), that means method of ReadJson
are running after calling it in TestOfUsingJson
. And in this case I didn't have to set up anything.
For the first application (ASP.NET MVC) I have a trouble, object are converted from json, but this object are not created from my custom converter. Method of ReadJson
are not running.
Method which who use custom converter are looks same on the every application
public HttpResponseMessage TestOfUsingJson([FromBody] CustomObject objs)
{
...
}
Some settings for Json Serializer in the ASP.NET MVC's Global.asax.cs
:
JsonConvert.DefaultSettings = () => new JsonSerializerSettings
{
Converters = new List<JsonConverter> { new MyCustomJsonConverter() }
};
What am I doing wrong?