summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/sql
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-08-08 23:34:20 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-08-08 23:52:51 -0400
commit104e6907284e602a8485f32fc67fd6af0c00e4d0 (patch)
treefd628fbc353341fa31953b5f55be98b9748e6bea /lib/sqlalchemy/sql
parentd8da7f5ac544f3dd853a221faa5fab4ff788e25b (diff)
downloadsqlalchemy-104e6907284e602a8485f32fc67fd6af0c00e4d0.tar.gz
Correct name for json_serializer / json_deserializer, document and test
The dialects that support json are supposed to take arguments ``json_serializer`` and ``json_deserializer`` at the create_engine() level, however the SQLite dialect calls them ``_json_serilizer`` and ``_json_deserilalizer``. The names have been corrected, the old names are accepted with a change warning, and these parameters are now documented as :paramref:`.create_engine.json_serializer` and :paramref:`.create_engine.json_deserializer`. Fixes: #4798 Change-Id: I1dbfe439b421fe9bb7ff3594ef455af8156f8851
Diffstat (limited to 'lib/sqlalchemy/sql')
-rw-r--r--lib/sqlalchemy/sql/sqltypes.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/sqltypes.py b/lib/sqlalchemy/sql/sqltypes.py
index 38731fcbe..631352ceb 100644
--- a/lib/sqlalchemy/sql/sqltypes.py
+++ b/lib/sqlalchemy/sql/sqltypes.py
@@ -2042,6 +2042,26 @@ class JSON(Indexable, TypeEngine):
values, but care must be taken as to the value of the
:paramref:`.JSON.none_as_null` in these cases.
+ The JSON serializer and deserializer used by :class:`.JSON` defaults to
+ Python's ``json.dumps`` and ``json.loads`` functions; in the case of the
+ psycopg2 dialect, psycopg2 may be using its own custom loader function.
+
+ In order to affect the serializer / deserializer, they are currently
+ configurable at the :func:`.create_engine` level via the
+ :paramref:`.create_engine.json_serializer` and
+ :paramref:`.create_engine.json_deserializer` parameters. For example,
+ to turn off ``ensure_ascii``::
+
+ engine = create_engine(
+ "sqlite://",
+ json_serializer=lambda obj: json.dumps(obj, ensure_ascii=False))
+
+ .. versionchanged:: 1.3.7
+
+ SQLite dialect's ``json_serializer`` and ``json_deserializer``
+ parameters renamed from ``_json_serializer`` and
+ ``_json_deserializer``.
+
.. seealso::
:class:`.postgresql.JSON`