![](/img/trans.png)
[英]Spring Boot 2 WebClient response convert JSON to HashMap
[英]Convert a hashmap to a json string in spring-boot
我正在创建一个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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.