{
  "id": "python/fastapi-jsonable-encoder-error",
  "signature": "TypeError: Object of type ObjectId is not JSON serializable",
  "signature_zh": "类型错误：ObjectId类型的对象无法JSON序列化",
  "regex": "TypeError:\\ Object\\ of\\ type\\ ObjectId\\ is\\ not\\ JSON\\ serializable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Returning MongoDB ObjectId or similar BSON types directly from a FastAPI route without converting them.",
  "root_cause_type": "generic",
  "root_cause_zh": "在FastAPI路由中直接返回MongoDB ObjectId或类似的BSON类型，而没有进行转换。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Converting ObjectId to str manually works but loses the original type information.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using json.dumps with a custom default function may not integrate with FastAPI's response model.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use Pydantic's Json type: from pydantic import Json\\nclass Item(BaseModel):\\n    id: Json[Any]",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.95,
      "how": "Convert ObjectId to str in the route: item['_id'] = str(item['_id'])",
      "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.83,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-07-01",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}