我有一個JSON響應,它看起來像下面如何解析使用Sprint的休息模板
{
"resourceType": "Topic",
"metadata": {
"lastUpdated": "2016-12-15T14:51:33.490-06:00"
},
"entry": [
{
"resource": {
"resourceType": "Outcome",
"issue": [
{
"response": "error",
"code": "exception"
},
{
"response": "success",
"code": "informational"
},
\t \t {
"response": "success",
"code": "informational"
}
]
}
},
{
"resource": {
"resourceType": "Data",
"id": "80",
"subject": {
"reference": "dataFor/80"
},
"created": "2016-06-23T04:29:00",
"status": "current"
}
},
\t {
"resource": {
"resourceType": "Data",
"id": "90",
"subject": {
"reference": "dataFor/90"
},
"created": "2016-06-23T04:29:00",
"status": "current"
}
}
]
}
數據和結果類擴展資源混合子對象的JSON。
我正在使用Spring RestTemplate.getForObject(url,someClass)。我得到以下錯誤
has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not read JSON: Unrecognized field "response" (Class com.model.Resource), not marked as ignorable
at [Source: [email protected]e67a;
據我瞭解,JSON是沒有得到解析到子類資源。我想要做類似RestTemplate.getForObject(url,someClass)的東西,但這不被java泛型(通配符)支持。請幫助
告訴我們你的'com.model.Resource'。 – Arpit