Difference between odatamediatypeformatter and jsonmediatypeformatter
I would like to understand the difference between OdataMediaTypeFormatter and JsonMediaTypeFormatter . I tried searching the internet but didn't get an answer for this. In my product, we recently discovered that OdataMediaTypeFormatter was being used when we assumed we were using JsonMediaTypeFormatter . Our clients are using json.net to serialize their objects, so I would like to switch to using JsonMediaTypeFormatter , but want to know what will change with this switch.
I am aware of one difference between the two - one regarding deserializing a "long" datatype. odata json requires long values ββto be specified, but json.net does not. As mentioned in this thread here - WinJS OData JSON
Any pointers to this would help. Many thanks!
source to share
ODataMediaTypeFormatter
is in namespace System.Web.Http.OData.Formatter
(aka ASP.NET Web API for OData V1-3) ββand System.Web.OData.Formatter
(aka ASP.NET Web API for OData V4). So it is a media type formatter for OData payload types (namely Atom and JSON light and JSON verbose for OData V3 and OData JSON for OData V4).
On the other hand, it JsonMediaTypeFormatter
belongs System.Net.Http.Formatting
. As such, it is a native part of the .NET framework for handling JSON payload. They all descend from System.Net.Http.Formatting.MediaTypeFormatter
, but they have their own serialization and deserialization implementations of various kinds of payloads, which they target accordingly.
To understand what OData JSON is, you can refer to this link OData JSON Format version 4.0 . From it you can see that it ODataMediaTypeFormatter
also deals with a lot of specific JSON elements and attributes related to OData that it JsonMediaTypeFormatter
doesn't know about.
So for your scenario, since you are using this generic JSON serializer: JSON.NET to serialize objects, there should be nothing negative about switching to use JsonMediaTypeFormatter
as long as your client is not talking to the OData service.
source to share