0

java.util.Set , java.util.List and other Collection interfaces are not serializable. Require a simple, direct solution to use this in a serializable POJO.

public class Employee implements Serializable{
    private int id;
    private String name;
    private Set<Address> address= new HashSet<Address>;
}
luckysuru
  • 1
  • 2

2 Answers2

1

HashSet is serializable [Documentation] as long as all the objects it contains are serializable, so you need to make sure that Address class is serializable.

Anand S Kumar
  • 88,551
  • 18
  • 188
  • 176
0

In this particular case there are two solutions. One is the approach used in the possible duplicate's answers. The other is to make the field type HashSet<Address> rather than Set<Address>. The field type should be the least specific type that supports all the features you intend to use.

Patricia Shanahan
  • 25,849
  • 4
  • 38
  • 75