Convert Map to JSON using Jackson
Solution 1:
You can convert Map
to JSON
using Jackson as follows:
Map<String,String> payload = new HashMap<>();
payload.put("key1","value1");
payload.put("key2","value2");
String json = new ObjectMapper().writeValueAsString(payload);
System.out.println(json);
Solution 2:
Using jackson, you can do it as follows:
ObjectMapper mapper = new ObjectMapper();
String clientFilterJson = "";
try {
clientFilterJson = mapper.writeValueAsString(filterSaveModel);
} catch (IOException e) {
e.printStackTrace();
}
Solution 3:
You should prefer Object Mapper instead. Here is the link for the same : Object Mapper - Spring MVC way of Obect to JSON