From 9dfcb90c92e13f2d92cb723cb834b5e0d666a2f5 Mon Sep 17 00:00:00 2001 From: Ties Jan Hefting Date: Wed, 6 Jul 2022 11:38:33 +0200 Subject: [PATCH] Document serialization of Decimal in JSONEncoder The Flask JSONEncoder serializes Decimal types to strings, but this behavior is missing from the docs. The docs are updated accordingly. --- docs/api.rst | 1 + src/flask/json/__init__.py | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/api.rst b/docs/api.rst index b3cffde26f..6b02494bff 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -242,6 +242,7 @@ for easier customization. By default it handles some extra data types: - :class:`datetime.datetime` and :class:`datetime.date` are serialized to :rfc:`822` strings. This is the same as the HTTP date format. +- :class:`decimal.Decimal` is serialized to a string. - :class:`uuid.UUID` is serialized to a string. - :class:`dataclasses.dataclass` is passed to :func:`dataclasses.asdict`. diff --git a/src/flask/json/__init__.py b/src/flask/json/__init__.py index edc9793df4..adefe02dcd 100644 --- a/src/flask/json/__init__.py +++ b/src/flask/json/__init__.py @@ -23,6 +23,7 @@ class JSONEncoder(_json.JSONEncoder): - :class:`datetime.datetime` and :class:`datetime.date` are serialized to :rfc:`822` strings. This is the same as the HTTP date format. + - :class:`decimal.Decimal` is serialized to a string. - :class:`uuid.UUID` is serialized to a string. - :class:`dataclasses.dataclass` is passed to :func:`dataclasses.asdict`.