Closed oddcc closed 5 years ago
I have also had the need to support text/xml where a 3rd party provider cannot change their content type value.
Instead of replicating the whole class, I simply just extended it and overwrote the media_type value.
media_type
from rest_framework_xml.parsers import XMLParser class TextXMLParser(XMLParser): media_type = "text/xml"
All that's needed is to add the custom parser to DRF settings:
REST_FRAMEWORK = { 'DEFAULT_PARSER_CLASSES': [ 'rest_framework.parsers.JSONParser', 'myapp.parsers.text_xml.TextXMLParser' ] ...
And that seems to work perfectly.
@oddcc thanks for the PR. @muhammedabad's comment shows a suggested workaround, which is also what I would recommend.
I have also had the need to support text/xml where a 3rd party provider cannot change their content type value.
Instead of replicating the whole class, I simply just extended it and overwrote the
media_type
value.All that's needed is to add the custom parser to DRF settings:
And that seems to work perfectly.