-
August 21st, 2015, 05:22 AM
#1
[RESOLVED] Web API: Disable default XML and JSON formatters for a specific type ?
I have a Web API 2 based webservice
it has a lot of API's returning various types that all get returned via the normal xml and json formatters.
ok so far.
I have a couple api's that return a type where the default xml/json doesn't do what I want,
That type has a custom formatter, which works if I set it to accept "text/mycustomformat".
If I ask for "application/xml" however, it appears the default formatter get prioritized.
So I was wondering if it is possible to
- disable the default xml/json formatters for that type only ?
- or make it pick my custom formatter over the more generic default ones
The type is returning an error at the moment because the default xml/json serializers can't handle it, and return a rather nasty error about that.
Last edited by OReubens; August 25th, 2015 at 06:46 AM.
-
August 25th, 2015, 06:45 AM
#2
Re: Web API: Disable default XML and JSON formatters for a specific type ?
issue resolved.
Instead of adding the new formatters tot the list of formatters in the config object, I am now inserting them at the front of the MediaTypeFormatterCollection.
in Global.asax.cs, at the end of Application_Start:
Code:
GlobalConfiguration.Configuration.Formatters.Insert(0, new WebConnect.WebService.Helpers.MyFormatter());
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|