1

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

informatik01
  • 16,038
  • 10
  • 74
  • 104
Cyber
  • 49
  • 1
  • 13

2 Answers2

3

Make your Keyword and Document classes implement java.io.Serializable.

Everything what you are trying to serialize should implement java.io.Serializable, HashMap and String by default are serializable so you need not to do anything for them.

Please read this.

hagrawal7777
  • 14,103
  • 5
  • 40
  • 70
0

Try to make Keyword implement java.io.Serializable