The ObjectMapper.convertValue () function is convenient and type aware. It can perform a wide range of conversions between tree nodes and Java types / sets and vice versa.
An example of how you can use it:
List<String> list = new ArrayList<>(); list.add("one"); list.add("two"); Map<String,List<String>> hashMap = new HashMap<>(); hashMap.put("myList", list); ObjectMapper mapper = new ObjectMapper(); ObjectNode objectNode = mapper.convertValue(hashMap, ObjectNode.class); Map<String,List<String>> hashMap2 = mapper.convertValue(objectNode, HashMap.class);
source share