[英]How to convert TreeMap with contents to JSON format Spring REST Controller JAVA
Hello I have a code where I want to expose my Collection as JSON format. 您好,我有一个代码想要在其中以JSON格式公开我的收藏。 I thought Spring does it automatically.
我以为Spring是自动完成的。 Here is the code:
这是代码:
@RestController
public class BirthdayController extends BaseController{
@RequestMapping("/api/v1/birthday")
public TreeMap<Integer, TreeMap<Integer, ArrayList<BirthdayDetails>>> getBirthdays(@RequestParam(value="startYear") Integer startYear,
@RequestParam(value="startMonth") Integer startMonth,
@RequestParam(value="endYear") Integer endMonth,
@RequestParam(value="endMonth") Integer endYear) {
BirthdayServiceImpl birthdayService = new BirthdayServiceImpl();
return birthdayService.getBirthdaysBetweenDate(startMonth, startYear, endMonth, endYear);
}
}
I get only empty {}
on accessing endpoint 我在访问端点时仅得到空
{}
try, 尝试,
@RequestMapping("/api/v1/birthday")
public @ResponseBody TreeMap<Integer, TreeMap<Integer, ArrayList<BirthdayDetails>>> getBirthdays(@RequestParam(value="startYear") Integer startYear,
@RequestParam(value="startMonth") Integer startMonth,
@RequestParam(value="endYear") Integer endMonth,
@RequestParam(value="endMonth") Integer endYear) {
BirthdayServiceImpl birthdayService = new BirthdayServiceImpl();
return birthdayService.getBirthdaysBetweenDate(startMonth, startYear, endMonth, endYear);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.