This question already has an answer here:
- java.io.NotSerializableException 3 answers
I have the following classes:
public class Document {
public String id;
public String date;
public Map<String, Keyword> keywords = new HashMap<>();
}
public class Keyword {
public String word;
public Map<String, Document> docs = new HashMap<>();
}
I want to serialize the keywords
HashMap in order to save it in Redis.
I tried this but it throws an error:
java.io.NotSerializableException:keyword
Try to make Keyword implement
java.io.Serializable
Make your
Keyword
andDocument
classes implementjava.io.Serializable
.Everything what you are trying to serialize should implement
java.io.Serializable
,HashMap
andString
by default are serializable so you need not to do anything for them.Please read this.