コード例 #1
0
 def to_json(self, *args, **kwargs):
     """Return the JSON representation of the data. Takes the same arguments
     as Python's built-in ``json.dumps``.
     """
     ret = self.opts.json_module.dumps(self.data, *args, **kwargs)
     # On Python 2, json.dumps returns bytestrings
     # On Python 3, json.dumps returns unicode
     # Ensure that a bytestring is returned
     if isinstance(ret, text_type):
         return binary_type(ret.encode('utf-8'))
     return ret
コード例 #2
0
ファイル: serializer.py プロジェクト: asteinlein/marshmallow
 def to_json(self, *args, **kwargs):
     '''Return the JSON representation of the data. Takes the same arguments
     as Pythons built-in ``json.dumps``.
     '''
     ret = self.opts.json_module.dumps(self.data, *args, **kwargs)
     # On Python 2, json.dumps returns bytestrings
     # On Python 3, json.dumps returns unicode
     # Ensure that a bytestring is returned
     if isinstance(ret, text_type):
         return binary_type(ret.encode('utf-8'))
     return ret
コード例 #3
0
 def test_json(self):
     json_data = self.serialized.json
     expected = binary_type(json.dumps(self.serialized.data).encode("utf-8"))
     assert_equal(json_data, expected)
コード例 #4
0
def test_json(serialized_user):
    json_data = serialized_user.json
    expected = binary_type(json.dumps(serialized_user.data).encode("utf-8"))
    assert json_data == expected
コード例 #5
0
def test_json(serialized_user):
    json_data = serialized_user.json
    expected = binary_type(json.dumps(serialized_user.data).encode("utf-8"))
    assert json_data == expected
コード例 #6
0
ファイル: test_schema.py プロジェクト: svenstaro/marshmallow
def test_dumps_returns_json(user):
    ser = UserSchema()
    serialized, errors = ser.dump(user)
    json_data, errors = ser.dumps(user)
    expected = binary_type(json.dumps(serialized).encode("utf-8"))
    assert json_data == expected