{
  "id": "python/sqlalchemy-json-serialization-error",
  "signature": "TypeError: Object of type User is not JSON serializable",
  "signature_zh": "TypeError: User 类型的对象无法进行 JSON 序列化",
  "regex": "TypeError:\\ Object\\ of\\ type\\ User\\ is\\ not\\ JSON\\ serializable",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "Trying to serialize SQLAlchemy model instances directly with json.dumps() without a custom encoder.",
  "root_cause_type": "generic",
  "root_cause_zh": "尝试直接用 json.dumps() 序列化 SQLAlchemy 模型实例，而没有自定义编码器。",
  "versions": [
    {
      "version": "1.4.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "2.0.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Returns the object's string representation, not the data.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Converts all non-serializable objects to strings, losing structure.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use a custom encoder: class UserEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, User): return {'id': obj.id, 'name': obj.name} return super().default(obj)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "Convert to dict first: user_dict = {c.name: getattr(user, c.name) for c in user.__table__.columns}",
      "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-03-25",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}