summaryrefslogtreecommitdiff
path: root/lib/utils/json.py
blob: 63b3cfb50b269f4f1e76c97717c5807d48f06815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Authors: see git history
#
# Copyright (c) 2010 Authors
# Licensed under the GNU GPL version 3.0 or later.  See the file LICENSE for details.

from flask.json import JSONEncoder


class InkStitchJSONEncoder(JSONEncoder):
    """JSON encoder class that runs __json__ on an object if available.

    The __json__ method should return a JSON-compatible representation of the
    object.
    """

    def default(self, obj):
        try:
            return obj.__json__()
        except AttributeError:
            return JSONEncoder.default(self, obj)