我正在创建一个spring-boot应用程序,我希望能够将hashmap的全部内容作为json字符串返回。我怎么做?
我的哈希图如下所示:
private static final Map<String,Animal> animalMap= new HashMap<String,Animal>();
功能
@RequestMapping(value="/animals", method=RequestMethod.GET) public String showAllAnimals() { // In here I want to return the content of my hashmap as a Json String }
@RequestMapping(value="/animals", method=RequestMethod.GET) @ResponseBody public Map<String,Animal> showAllAnimals() { return animalMap; }