How to make a class serializable if it include a field of "Object"
java
Solution
"Object value" could be Integer, String...
Integer and String are both serializable. It will work. You don't need to do anything special to serialize them.
Is there a general serializable Object type?
Yeah, Serializable:
private Serializable value;
Problem
``` public class A implements Serializable { private static final long serialVersionUID = 1L; private Object value; private Type type; .... } ``` It includes "Object" which is not serializable, so class A will be rendered as not serializable. "Object value" could be Integer, String..., depending on "Type type" How to make A serializable? Thanks in advance! EDIT: Will "Object value" get lost (when de-serialing) if using "private transient Object value"? I don't want to lost it. Is there a general serializable Object type?