Access the default JSON.NET serializer in the ASP.NET web interface

I have an ASP.NET web API project, and since it does not support the presence of two body parameters, I use the JObject parameter and then extract the actual parameters from it. Like this.

Public bool mymethod(JObject data){ myclassA a = data["a"].toObject<myclassA>(); myclassA b = data["b"].toObject<myclassB>(); } 

But 2 types of classes implement ISerializable, and I need JSON.NET to ignore it. I installed the default JSON.NET serializer to do this, and it works fine when serialization is done automatically.

But I need to get a link to the built-in JSON.NET serializer so that I can use it like in the code above.

 myclassA b = data["b"].toObject<myclassB>(defaultSerializer); 

I am currently creating a new instance of the JSON.NET serializer and using it. But how can I get a link to the default built-in serializer in asp.net WEB API?

Also, I can’t change anything in class types, as this is a kind of obsolete application that I convert to web api. Thank.

+3
asp.net-web-api
Mar 13 '13 at 14:43
source share
1 answer

Try the following:

 JsonSerializer serializer = JsonSerializer.Create(Configuration.Formatters.JsonFormatter.SerializerSettings); 

This should give you the same serializer API that is used.

+8
Mar 13 '13 at 20:34
source share



All Articles