我正在使用杰克逊和弹簧从我的api获取一个物体。我将一个带有3个对象的数组返回到一个名为interviewList的对象,该对象具有对象访谈,候选人和工作。然而在json中,这是嵌套在称为“访谈”的包装器中,因为路径是/ users / id / interview。所以它看起来像这样:
{"interviews":
[[
"interviews",[
{"id":1...},
{"id":2...}
]],
"candidates", [
{"id":1...},
{"id":2...}
]]
"jobs", [
{"id":1...},
{"id":2...}
]]
["status",201]
]}
但是我一直收到错误:
An exception occurred during request network execution :Could not read JSON: Root name
'interviews' does not match expected ('interviewsList') for type [simple type, class
com.example.model.InterviewsList]
这是我的容器interviewList:
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonRootName(value="interviews")
public class InterviewsList {
private ArrayList<InterviewEntry> interviews;
private ArrayList<User> Candidates;
private ArrayList<Job> Jobs;
//getter and setters
}
我的请求电话
response = restTemplate.getForObject(Config.WEB_SERVICE_URL + "users/"+userID+"/interviews", InterviewsList.class);
我的api回归
render json: {interviews:interviewsList, candidates:candidatesList, status: 201}
显然我搞乱了筑巢。我该怎么解决这个问题?我是否需要忽略根或者我的渲染可能有问题?