# TypeError: Object of type User is not JSON serializable

- **ID:** `python/sqlalchemy-json-serialization-error`
- **Domain:** python
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Trying to serialize SQLAlchemy model instances directly with json.dumps() without a custom encoder.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.4.x | active | — | — |
| 2.0.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   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)
   ```
2. **** (85% success)
   ```
   Convert to dict first: user_dict = {c.name: getattr(user, c.name) for c in user.__table__.columns}
   ```

## Dead Ends

- **** — Returns the object's string representation, not the data. (80% fail)
- **** — Converts all non-serializable objects to strings, losing structure. (70% fail)
