{
  "id": "python/pydantic-model-dump-json-not-serializable",
  "signature": "pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'datetime.date'>",
  "signature_zh": "pydantic_core._pydantic_core.PydanticSerializationError: 无法序列化未知类型: <class 'datetime.date'>",
  "regex": "pydantic_core\\._pydantic_core\\.PydanticSerializationError:\\ Unable\\ to\\ serialize\\ unknown\\ type:\\ <class\\ 'datetime\\.date'>",
  "domain": "python",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "model_dump_json or model_dump(mode='json') encountered a type with no registered serializer, often a custom class or a third-party object stored in an Any field.",
  "root_cause_type": "generic",
  "root_cause_zh": "model_dump_json 或 model_dump(mode='json') 遇到没有注册序列化器的类型，通常是 Any 字段中的自定义类或第三方对象。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "model_dump() returns Python objects, so json.dumps fails with the same underlying non-serializable type error.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changes validation semantics and loses type information for all consumers, not just serialization.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.93,
      "how": "from datetime import date\nfrom pydantic import BaseModel, field_serializer\n\nclass Model(BaseModel):\n    d: date\n\n    @field_serializer('d')\n    def ser_date(self, v: date, _info):\n        return v.isoformat()",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from typing import Annotated\nfrom pydantic import PlainSerializer\n\nIsoDate = Annotated[date, PlainSerializer(lambda v: v.isoformat(), return_type=str)]",
      "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.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-05-30",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}