33"""This module contains the logic of resource management"""
44
55import inspect
6- import json
76from six import with_metaclass
87
98from werkzeug .wrappers import Response
10- from flask import request , url_for , make_response , current_app
9+ from flask import request , url_for , make_response , current_app , jsonify
1110from flask .views import MethodView , MethodViewType
1211from marshmallow_jsonapi .exceptions import IncorrectTypeError
1312from marshmallow import ValidationError
@@ -70,14 +69,14 @@ def dispatch_request(self, *args, **kwargs):
7069 try :
7170 response = method (* args , ** kwargs )
7271 except JsonApiException as e :
73- return make_response (json . dumps (jsonapi_errors ([e .to_dict ()])),
72+ return make_response (jsonify (jsonapi_errors ([e .to_dict ()])),
7473 e .status ,
7574 headers )
7675 except Exception as e :
7776 if current_app .config ['DEBUG' ] is True :
7877 raise e
7978 exc = JsonApiException ('' , str (e ))
80- return make_response (json . dumps (jsonapi_errors ([exc .to_dict ()])),
79+ return make_response (jsonify (jsonapi_errors ([exc .to_dict ()])),
8180 exc .status ,
8281 headers )
8382
@@ -88,7 +87,7 @@ def dispatch_request(self, *args, **kwargs):
8887 if not isinstance (response , tuple ):
8988 if isinstance (response , dict ):
9089 response .update ({'jsonapi' : {'version' : '1.0' }})
91- return make_response (json . dumps (response ), 200 , headers )
90+ return make_response (jsonify (response ), 200 , headers )
9291
9392 try :
9493 data , status_code , headers = response
@@ -104,7 +103,7 @@ def dispatch_request(self, *args, **kwargs):
104103 if isinstance (data , dict ):
105104 data .update ({'jsonapi' : {'version' : '1.0' }})
106105
107- return make_response (json . dumps (data ), status_code , headers )
106+ return make_response (jsonify (data ), status_code , headers )
108107
109108
110109class ResourceList (with_metaclass (ResourceMeta , Resource )):
0 commit comments