我休息web服務(含球衣),返回JSON的列表請求休息JSON的服務,如果我把它直接返回正是這一點:產生javax.xml.bind.UnmarshalException當球衣客戶
[{"success":false,"uri":"foo:22","message":"Unknown host : foo"},{"success":true,"uri":"localhost:8082","message":null}]
通過這個片段:
@GET
@Path("/opening/")
public List<OpeningResult> testOpenings(@QueryParam("uri") List<String> uris) {
LOG.debug("testOpenings request uris :[" + uris + "]");
List<OpeningResult> openingResults = infoService.testOpenings(uris);
return openingResults;
}
這是一個POJO集合看起來是這樣的:
@XmlRootElement(name = "OpeningResult")
public class OpeningResult {
attributes
...
getter/setter
}
這個POJO的是通過服務器和客戶端之間的通用jar進行共享。
我調用Web服務在這個片段:
Client client = Client.create();
WebResource resource = client.resource("http://localhost:8080/scheduler/rest/opening");
MultivaluedMap<String, String> params = new MultivaluedMapImpl();
for (String uri : uris) {
params.add("uri", uri);
}
List<OpeningResult> results = newArrayList(resource.queryParams(params).get(OpeningResult[].class));
我添加服務器端的一些痕跡,我看到我的其他服務被稱爲與良好的參數,在客戶端buth,我有這個錯誤:
Caused by: javax.xml.bind.UnmarshalException: unexpected element (uri:"", local:"success"). Expected elements are <{}OpeningResult>
我不知道它來自哪裏?
你可以發佈發佈Pojo的服務器端代碼嗎? – 2012-04-13 13:05:05
我編輯我的消息與片段。 – Antoine 2012-04-17 09:48:45