Say I define a class as follows:
public class Foo {
[JsonProperty(PropertyName = "custoomername")]
public string CustomerName { get; set; }
}
Notice that I'm expecting to read/write some bad JSON. Not invalid syntax, but perhaps another developer has a spelling error I need to workaround (custoomer instead of customer).
Now, in my controller I have this method:
public ActionResult DoSomething(Foo foo) {
return Json(foo);
}
I want the input object foo
and the returned JSON from foo
to both use NewtonSoft and not the internal JavascriptSerializer that is default on MVC.
I was able to solve the output only so far using this example. However, the input doesn't work. I tried replacing the ValueFactoryProvider
for the JsonValueProviderFactory
with this example however that doesn't appear to understand what object type the requesting method will want.
Is it possible to do this?
[Edit:] Under the proposed duplicate's answer the ExpandoObject
is used and a DictionaryValueProvider
is created. This still has the bad JSON in it and does not deserialize into my class.