# TypeError: Object of type Decimal is not JSON serializable

- **ID:** `python/flask-jsonify-error-non-serializable`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Flask 的 jsonify 函数无法序列化 Decimal 类型数据

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.9 | active | — | — |
| 3.10 | active | — | — |

## Workarounds

1. **自定义 JSON 编码器** (95% success)
   ```
   from flask import Flask, jsonify
from decimal import Decimal
class CustomJSONEncoder(JSONEncoder):
    def default(self, obj):
        if isinstance(obj, Decimal):
            return float(obj)
        return super().default(obj)
app.json_encoder = CustomJSONEncoder
   ```
2. **手动转换为 float 或 str** (90% success)
   ```
   data = {'price': float(decimal_value)}
   ```

## Dead Ends

- **使用 str() 转换但丢失精度** — Decimal 精度可能丢失 (60% fail)
- **使用 json.dumps 替代 jsonify** — Flask 响应需要特定格式 (70% fail)
