Implement this method in a subclass such that it returns a serializable object for ``o``, or calls the base implementation (to raise a ``TypeError``). For example, to support arbitrary iterators, you could implement default like this:: def default(self,
(self, o)
| 269 | self.encoding = encoding |
| 270 | |
| 271 | def default(self, o): |
| 272 | """Implement this method in a subclass such that it returns |
| 273 | a serializable object for ``o``, or calls the base implementation |
| 274 | (to raise a ``TypeError``). |
| 275 | |
| 276 | For example, to support arbitrary iterators, you could |
| 277 | implement default like this:: |
| 278 | |
| 279 | def default(self, o): |
| 280 | try: |
| 281 | iterable = iter(o) |
| 282 | except TypeError: |
| 283 | pass |
| 284 | else: |
| 285 | return list(iterable) |
| 286 | return JSONEncoder.default(self, o) |
| 287 | |
| 288 | """ |
| 289 | raise TypeError('Object of type %s is not JSON serializable' % |
| 290 | o.__class__.__name__) |
| 291 | |
| 292 | def encode(self, o): |
| 293 | """Return a JSON string representation of a Python data structure. |
nothing calls this directly
no outgoing calls
no test coverage detected