的json養神看起來像下面在Java JSON動態反序列化
{
"duration": 0,
"taskSummaries": [
{
"name": null,
"id": 151,
"priority": 0,
"content": "{\"Comment\":\"Employee:{name}\",\"TaskName\":\"employeeForm\",\"GroupId\":\"HR\",\"NodeName\":\"Employee Form\"}",
"processId": "demoProject1.busiProce1",
"description": null,
"subject": null,
"statusMessage": "Ready",
"itemID": "com.demo.tp15:demoProject1:1.0",
"potentialOwners": [
{
"name": "mary",
"type": "USER"
}
],
"skippable": true,
"actualOwner": null,
"createdBy": null,
"createdOn": null,
"activationTime": 1412582092211,
"processInstanceId": 172,
"processSessionId": 0,
"quickTaskSummary": null,
"parentId": null
}
],
"statusMessage": "200",
"itemID": null,
"processInstanceId": 172,
"startURL": null,
"processAppID": "demoProject1.busiProce1",
"processAppName": null,
"processState": {
"description": "Active",
"code": 1
},
"dueDate": null,
"startDt": null,
"endDt": null,
"parentProcessInstanceId": 0,
"outcome": null,
"identity": null,
"processVersion": null,
"processName": null,
"externalId": null
}
和我沒有在我的POJO /模型對象也控制......按我的編碼標準,我必須遵循命名約定例如taskSummaries將tskSumris,名字是NME,員工是empl的..
我的問題在這裏: 我想我的JSON字符串動態地分配給我的POJO /模型時在JSON字符串和POJO犯規匹配名稱。
我知道(其實我也做),如果我有名稱匹配的話,我可以做這樣的事情
private Object getDynamicObject(String jsonString,Class class1) throws JsonParseException, JsonMappingException, IOException{
ObjectMapper mapper = new ObjectMapper();
Object dynamicObject = null;
dynamicObject = mapper.readValue(jsonString, class1);
return dynamicObject;
}
你們能幫幫我。
爲了您的信息,我的樣本POJO可能看起來像下面: – Manjeet 2014-10-06 10:45:46
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(NAME = 「ProcessKey」,propOrder = { 「prcsNme」, 「dplyNme」 }) 公共類ProcessKey { @XmlElement(name =「PrcsNme」,required = true) protected String prcsNme; @XmlElement(name =「DplyNme」,required = true) protected String dplyNme; public String getPrcsNme(){ return prcsNme; } 公共無效setPrcsNme(字符串值){ this.prcsNme =值; } 公共字符串getDplyNme(){ 返回dplyNme; } 公共無效setDplyNme(字符串值){ 此。dplyNme =值; } } – Manjeet 2014-10-06 10:48:47