Skip to content
Myr

Added support for UUID objects to JSON serializer as well

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 18673ba · Browse files · 1 file+6 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−3 removed

  • other:+6 added−3 removed

1 file+6 added−3 removed

modified:flask/json.py+6 added-3 removed
6 unmodified lines
78 :copyright: (c) 2012 by Armin Ronacher.9 :license: BSD, see LICENSE for more details.10"""11import uuid12from datetime import datetime13from .globals import current_app, request1415from werkzeug.http import http_date
14 unmodified lines
303132class JSONEncoder(_json.JSONEncoder):33 """The default Flask JSON encoder. This one extends the default simplejson33 encoder by also supporting ``datetime`` objects as well as ``Markup``34 objects which are serialized as RFC 822 datetime strings (same as the HTTP35 date format). In order to support more data types override the34 encoder by also supporting ``datetime`` objects, ``UUID`` as well as35 ``Markup`` objects which are serialized as RFC 822 datetime strings (same36 as the HTTP date format). In order to support more data types override the37 :meth:`default` method.38 """3940 def default(self, o):
14 unmodified lines
55 return JSONEncoder.default(self, o)56 """57 if isinstance(o, datetime):58 return http_date(o)59 if isinstance(o, uuid.UUID):60 return str(o)61 if hasattr(o, '__html__'):62 return unicode(o.__html__())63 return _json.JSONEncoder.default(self, o)64
108 unmodified lines