For string body make sure we serialize unicode properly

This commit is contained in:
Honza Král
2013-12-04 13:22:33 +01:00
parent 19f9eaab95
commit 4420296636
+5 -1
View File
@@ -21,7 +21,11 @@ class JSONSerializer(object):
def dumps(self, data):
# don't serialize strings
if isinstance(data, (type(''), type(u''))):
return data
try:
return data.encode('utf-8')
except UnicodeDecodeError:
# Python 2 and str, no need to re-encode
return data
try:
return json.dumps(data, default=self.default)