Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
ec8098b7
Commit
ec8098b7
authored
Sep 28, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work around 2.x/3.x json.dumps() return type fuzziness
parent
10dbf131
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
rest_framework/fields.py
+5
-1
tests/test_fields.py
+2
-2
No files found.
rest_framework/fields.py
View file @
ec8098b7
...
@@ -1544,7 +1544,11 @@ class JSONField(Field):
...
@@ -1544,7 +1544,11 @@ class JSONField(Field):
def
to_representation
(
self
,
value
):
def
to_representation
(
self
,
value
):
if
self
.
binary
:
if
self
.
binary
:
return
json
.
dumps
(
value
)
value
=
json
.
dumps
(
value
)
# On python 2.x the return type for json.dumps() is underspecified.
# On python 3.x json.dumps() returns unicode strings.
if
isinstance
(
value
,
six
.
text_type
):
value
=
bytes
(
value
.
encode
(
'utf-8'
))
return
value
return
value
...
...
tests/test_fields.py
View file @
ec8098b7
...
@@ -1562,7 +1562,7 @@ class TestBinaryJSONField(FieldValues):
...
@@ -1562,7 +1562,7 @@ class TestBinaryJSONField(FieldValues):
Values for `JSONField` with binary=True.
Values for `JSONField` with binary=True.
"""
"""
valid_inputs
=
[
valid_inputs
=
[
(
'{"a": 1, "3": null, "b": ["some", "list", true, 1.23]}'
,
{
(
b
'{"a": 1, "3": null, "b": ["some", "list", true, 1.23]}'
,
{
'a'
:
1
,
'a'
:
1
,
'b'
:
[
'some'
,
'list'
,
True
,
1.23
],
'b'
:
[
'some'
,
'list'
,
True
,
1.23
],
'3'
:
None
'3'
:
None
...
@@ -1576,7 +1576,7 @@ class TestBinaryJSONField(FieldValues):
...
@@ -1576,7 +1576,7 @@ class TestBinaryJSONField(FieldValues):
'a'
:
1
,
'a'
:
1
,
'b'
:
[
'some'
,
'list'
,
True
,
1.23
],
'b'
:
[
'some'
,
'list'
,
True
,
1.23
],
'3'
:
None
'3'
:
None
},
'{"a": 1, "3": null, "b": ["some", "list", true, 1.23]}'
),
},
b
'{"a": 1, "3": null, "b": ["some", "list", true, 1.23]}'
),
]
]
field
=
serializers
.
JSONField
(
binary
=
True
)
field
=
serializers
.
JSONField
(
binary
=
True
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment