Skip to content

Commit

Permalink
Merge pull request #25 from dealertrack/renderer
Browse files Browse the repository at this point in the history
fixing DoubleAsStrJsonEncoder for additional types
  • Loading branch information
miki725 committed Nov 21, 2018
2 parents 09d77f1 + 3061f15 commit b7ed129
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Expand Up @@ -3,6 +3,11 @@
History
-------

0.3.2 (2018-11-21)
~~~~~~~~~~~~~~~~~~

* Fixing ``DoubleAsStrJsonEncoder`` by subclassing from DRF which supports datetimes, etc

0.3.1 (2018-11-07)
~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion drf_braces/__init__.py
Expand Up @@ -4,4 +4,4 @@

__author__ = 'Miroslav Shubernetskiy'
__email__ = 'miroslav@miki725.com'
__version__ = '0.3.1'
__version__ = '0.3.2'
2 changes: 1 addition & 1 deletion drf_braces/renderers.py
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
from collections import Mapping
from json import JSONEncoder

import six
from rest_framework.renderers import JSONRenderer
from rest_framework.utils.encoders import JSONEncoder


class DoubleAsStrJsonEncoder(JSONEncoder):
Expand Down
13 changes: 11 additions & 2 deletions drf_braces/tests/test_renderers.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import datetime
import json
import unittest

Expand All @@ -9,6 +10,14 @@
class TestDoubleAsStrJsonEncoder(unittest.TestCase):
def test_encode(self):
self.assertEqual(
json.loads(json.dumps({'a': 12345678901234567890, 'b': [123]}, cls=DoubleAsStrJsonEncoder)),
{'a': '12345678901234567890', 'b': [123]}
json.loads(json.dumps({
'a': 12345678901234567890,
'b': [123],
'c': datetime.date(2010, 1, 2)
}, cls=DoubleAsStrJsonEncoder)),
{
'a': '12345678901234567890',
'b': [123],
'c': '2010-01-02',
}
)

0 comments on commit b7ed129

Please sign in to comment.