From 1123bf1011d7a4d4015660969428b557bcdc9479 Mon Sep 17 00:00:00 2001 From: Alexandre Figura Date: Thu, 10 Sep 2015 17:56:42 +0200 Subject: [PATCH] Update JSONParser decoding behavior Allow to define a decoder class for the JSONParser. --- rest_framework/parsers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework/parsers.py b/rest_framework/parsers.py index 2dc808f1a..317eef1b8 100644 --- a/rest_framework/parsers.py +++ b/rest_framework/parsers.py @@ -53,6 +53,7 @@ class JSONParser(BaseParser): """ media_type = 'application/json' + decoder_class = json.JSONDecoder renderer_class = renderers.JSONRenderer def parse(self, stream, media_type=None, parser_context=None): @@ -64,7 +65,7 @@ class JSONParser(BaseParser): try: data = stream.read().decode(encoding) - return json.loads(data) + return json.loads(data, cls=self.decoder_class) except ValueError as exc: raise ParseError('JSON parse error - %s' % six.text_type(exc))