{
  "id": "python/starlette-json-response-non-serializable",
  "signature": "TypeError: Object of type datetime is not JSON serializable",
  "signature_zh": "类型错误：datetime 类型的对象无法进行 JSON 序列化",
  "regex": "TypeError:\\ Object\\ of\\ type\\ datetime\\ is\\ not\\ JSON\\ serializable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "在 Starlette 的 JSONResponse 中直接返回了 datetime 对象，而标准 JSON 序列化不支持该类型。",
  "root_cause_type": "generic",
  "root_cause_zh": "在 Starlette 的 JSONResponse 中直接返回了 datetime 对象，而标准 JSON 序列化不支持该类型。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "虽然能序列化，但格式不可控，前端解析困难。",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Starlette 的 JSONResponse 不接受自定义序列化器，此方法无效。",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "data = {'time': datetime.now().isoformat()}\nreturn JSONResponse(data)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from starlette.responses import JSONResponse\nclass CustomJSONResponse(JSONResponse):\n    def render(self, content):\n        return json.dumps(content, default=str).encode()",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-09-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}