【发布时间】:2018-03-15 09:21:33
【问题描述】:
我的模型如下所示,其中 bookJson 是一个 json 对象 -
{
"name" : "somebook",
"author" : "someauthor"
}
public class Book{
private int id;
private JSONObject bookJson;
public int getId(){return this.id;}
public JSONObject getBookJson(){this.bookJson;}
public void setId(int id){this.id = id;}
public void setBookJson(JSONObject json){this.bookJson = json;}
}
JSONObject 属于 org.json 包
当我的 RestController 在 ResponseEntity 对象中返回 Book 对象时,我收到错误 -
"errorDesc": "Type definition error: [simple type, class org.json.JSONObject]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
实现这一目标的最佳方法是什么?
如果没有一个包含 bookJson 的所有字段的模型类,我们不能实现这一点吗?
【问题讨论】:
-
你是如何从控制器层发送这个对象的?
-
作为列表
标签: json rest spring-restcontroller objectmapper