publicclassClass{ private Map<Student, List<Student>> teamMap; // getter and setter }
// Test Code publicstaticvoidmain(String[] args)throws IOException { Class c = new Class();
Student leader = new Student(); leader.setAge(20); leader.setName("Salty Egg");
Student s = new Student(); s.setAge(20); s.setName("Sweet Egg"); Map<Student, List<Student>> map = new HashMap<>(); List<Student> list = new ArrayList<>(); list.add(s); map.put(leader, list); c.setTeamMap(map);
ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(c); System.out.println(json); // this line can be printed
Class _c = mapper.readValue(json, Class.class); System.out.println(_c.getTeamMap()); }
For serialization, there will not be any problem, and we can have the print-out
publicclassKeyValueContainer<K, V> { private K key; private V value;
publicKeyValueContainer(){} // this is required by Jackson publicKeyValueContainer(K key, V value){ this.key = key; this.value = value; } // getter and setter }