import datetime as dt from decimal import Decimal from typing import Any from molten import JSONRenderer, is_schema, dump_schema class ExtJSONRender(JSONRenderer): """JSON Render with support for ISO 8601 datetime format strings""" def default(self, ob: Any) -> Any: """You may override this when subclassing the JSON renderer in order to encode non-standard object types. """ if is_schema(type(ob)): return dump_schema(ob) if isinstance(ob, dt.datetime): return ob.isoformat() if isinstance(ob, Decimal): return float(ob) raise TypeError(f"cannot encode values of type {type(ob)}") # pragma: no cover