下面是我写的代码。Spring无法使用null键返回JSON响应
@RequestMapping(value = "/getData", method = RequestMethod.GET)
public @ResponseBody Map<String,String> test() throws IOException {
Map<String,String> map = new HashMap<String,String>();
map.put("key","value");
map.put(null, "Key's Value"); //**This highlighted code causing the problem, if I remove this then it works fine.**
return map;
}
当我命中URL localhost:8080/myapp/getData
收到以下响应
10.5.1 500内部服务器错误 服务器遇到阻止其完成请求的意外情况。
即使Spring也不打印任何服务器端异常!
我想知道为什么Spring无法处理JSON响应并将其作为null的根本原因。
我明白为什么它会失败,虽然Spring应该会在服务器端产生异常,因为它很难找到。我提供的代码是复制问题的示例代码。实际上,我不得不通过大量的代码行来找到根源。 – Zaid