Serializable a object properties too

java, object-serialization, serializable

Solution

Yes, you do; if your classes `Task` and `Role` are not `Serializable`, you'll get a `java.io.NotSerializableException` if you try to serialize an instance of `User`.

Ofcourse, if `Task` or `Role` contain other non-primitive, non-transient fields, they would have to be `Serializable` too, etc.

Problem

When I have `Serializable` in a class, do I need to add `Serializable` to all my objects within the class? For example, ``` public class User implements Serializable{ private List<Role> role; private Task task; } ``` Do I need to add `Serializable` to `Role` and `Task`, too? ``` public class Task implements Serializable{ // ... } public class Role implements Serializable{ // ... } ```

Original source

Related problems