java - com.fasterxml.jackson.databind.JsonMappingException 同时发送 Json
问题描述
我无法通过休息控制器发送 JsonObject:无法写入 HTTP 消息:org.springframework.http.converter.HttpMessageNotWritableException:无法写入 JSON:JsonObject;嵌套异常是 com.fasterxml.jackson.databind.JsonMappingException: JsonObject (通过引用链:com.google.gson.JsonObject[0]->com.google.gson.JsonObject["asString"])
private String str = "{ \"document\": [\n" +
" {\n" +
" \"file\": \"PayrollFAQ.pdf\",\n" +
" \"type\": \"pdf\",\n" +
" \"title\": \" FAQ for Payroll\",\n" +
" \"rating\": 4.5,\n" +
" \"confidence\": 0.9\n" +
" }\n" +
" ]}";
@RequestMapping(value = "/posttest", method = RequestMethod.POST, produces="application/json" )
public @ResponseBody ResponseEntity posttest(@RequestBody Information inputReq) {
JsonParser jsonParser = new JsonParser();
List testArray = new ArrayList();
JsonObject objectFromString = jsonParser.parse(str).getAsJsonObject();
testArray.add(HrBotUtilities.getArrayJSON(objectFromString, "document"));
System.out.println("testString : "+testArray.get(0));
return ResponseEntity.status(HttpStatus.OK).body(testArray.get(0));
}
// HrBotUtilities.getArrayJSON Method
public static JsonObject[] getArrayJSON(JsonObject docObj, String name) {
JsonObject[] list = null;
if (docObj.has(name)) {
JsonArray json;
json = docObj.getAsJsonArray(name);
int lenFeatures = json.size();
list = new JsonObject[lenFeatures];
for (int j = 0; j < lenFeatures; j++) {
JsonObject f = json.get(j).getAsJsonObject();
list[j] = f;
}
}
return list;
}
请帮我
解决方案
推荐阅读
- python - systemd 中的 Python 脚本:虚拟环境或真实环境
- sql - 如何在 THEN 中为 SQL 中的 where 子句提供多个值
- javascript - 引导模式窗口未正确显示且在 ASP.NET MVC 应用程序中未正确运行
- google-chrome - 获取控制台错误'Uncaught TypeError:无法读取此行的属性'run' of undefined':google.script.run
- reactjs - React / Typescript “无类型函数调用可能不接受类型参数。”
- java - 除非我按下主页按钮并重新进入活动,否则 RecyclerView 不显示任何项目
- javascript - Vuejs:奇怪的类渲染
- amazon-redshift - Redshift - 无法将查询结果加载到表中 - 领导节点问题
- web-applications - 从 WebApp 连接到 LAN 上的设备
- r - 使用R增加ggplot中log x轴某些值之间的分辨率?