java
runtime_error
ai_generated
true
java.io.NotSerializableException: com.example.MyClass
ID: java/not-serializable-exception
92%Fix Rate
87%Confidence
1Evidence
2024-01-05First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Java 8 | active | — | — | — |
| Java 11 | active | — | — | — |
| Java 17 | active | — | — | — |
| Java 21 | active | — | — | — |
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.
generic中文
尝试序列化未实现 java.io.Serializable 接口的类的对象,通常发生在对象输出、RMI 或会话复制过程中。
Official Documentation
https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/NotSerializableException.htmlWorkarounds
-
95% success Implement java.io.Serializable in the class: public class MyClass implements Serializable { private static final long serialVersionUID = 1L; }
Implement java.io.Serializable in the class: public class MyClass implements Serializable { private static final long serialVersionUID = 1L; } -
75% success If the class cannot be modified, use a custom serialization mechanism like Jackson or writeExternal for Externalizable.
If the class cannot be modified, use a custom serialization mechanism like Jackson or writeExternal for Externalizable.
中文步骤
Implement java.io.Serializable in the class: public class MyClass implements Serializable { private static final long serialVersionUID = 1L; }If the class cannot be modified, use a custom serialization mechanism like Jackson or writeExternal for Externalizable.
Dead Ends
Common approaches that don't work:
-
90% fail
The serialVersionUID field is only relevant for Serializable classes; without implementing the interface, the exception persists.
-
80% fail
Transient fields prevent serialization of those fields, but the class itself must still implement Serializable to be serialized.