# java.io.NotSerializableException: com.example.MyClass

- **ID:** `java/not-serializable-exception`
- **Domain:** java
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 92%

## Root Cause

An object of a class that does not implement java.io.Serializable is being serialized, typically during object output, RMI, or session replication.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## Workarounds

1. **Implement java.io.Serializable in the class: public class MyClass implements Serializable { private static final long serialVersionUID = 1L; }** (95% success)
   ```
   Implement java.io.Serializable in the class: public class MyClass implements Serializable { private static final long serialVersionUID = 1L; }
   ```
2. **If the class cannot be modified, use a custom serialization mechanism like Jackson or writeExternal for Externalizable.** (75% success)
   ```
   If the class cannot be modified, use a custom serialization mechanism like Jackson or writeExternal for Externalizable.
   ```

## Dead Ends

- **** — The serialVersionUID field is only relevant for Serializable classes; without implementing the interface, the exception persists. (90% fail)
- **** — Transient fields prevent serialization of those fields, but the class itself must still implement Serializable to be serialized. (80% fail)
