我打電話給服務,讓我回作爲輸出參數java.util.Collection
。現在我的問題是如何從該對象中檢索數據?如果我用Java打印它,我會得到類似於[[Ljava.lang.Object;@7ff4d7c0]
的東西。這很正常,因爲我只是在打印對象。java.util.collection從webservice返回
此服務來自ofbiz項目,它的工作正常。當我使用來自ofbiz的Web服務測試儀時,我得到如下返回值:
{{party=[GenericEntity:Party][partyId,10045(java.lang.String)][partyTypeId,PERSON(java.lang.String)]}, {party=[GenericEntity:Party][partyId,10119(java.lang.String)][partyTypeId,PERSON(java.lang.String)]}}`
如何在Java中實現此目的?
這是我的代碼:
public static void main(String[] args) throws MalformedURLException, XmlRpcException {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:8080/webtools/control/xmlrpc"));
config.setEnabledForExceptions(true);
config.setEnabledForExtensions(true);
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
Map paramMap = new HashMap();
Map map1 = new HashMap();
//Verplichte parameters
paramMap.put("login.username", "admin");
paramMap.put("login.password", "opentaps");
paramMap.put("userLoginId", "David");
Object[] params = new Object[]{paramMap};
Map result = (Map) client.execute("getPartyFromUserLogin", params);
//System.out.println(result.values());
Collection parties = null;
parties = (Collection) result.values();
System.out.println("Got parties: " + parties.size());
System.out.println(parties.toString());
Iterator it = parties.iterator();
while(it.hasNext()){
Party object = (Party)it.next();
System.out.println("ok : "+ object.getPartyId());
}
}
好了,所以現在我想重複它,將其轉換爲黨的對象(import org.opentaps.base.entities.Party;
)。猜猜它只是錯誤的課程?
錯誤日誌:
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to org.opentaps.base.entities.Party
at test.xmlrpcGetPartyEmail.main(xmlrpcGetPartyEmail.java:56)
錯誤日誌使用此代碼後:
Iterator it = parties.iterator();
while(it.hasNext()){
System.out.println("ok : "+ it.next().getClass());
}
class java.util.HashMap$Values
Got parties: 1
[[Ljava.lang.Object;@2380bfe1]
ok : class [Ljava.lang.Object;
服務器日誌:
ava:777:WARN ] Running the getPartyFromUserLogin Service...
[java] 2012-03-27 14:47:28,861 (http-0.0.0.0-8080-1) [ PartyServices.
ava:792:INFO ] PartyFromUserLogin number found: 2
[java] 2012-03-27 14:47:28,865 (http-0.0.0.0-8080-1) [ RequestHandler.
ava:641:INFO ] Ran Event [xmlrpc:#] from [request], result is [null]
[java] 2012-03-27 14:47:28,866 (http-0.0.0.0-8080-1) [ ControlServlet.
ava:328:INFO ] [[[xmlrpc] Request Done- total:0.056,since last([xmlrpc] Request
...):0.056]]
你有沒有嘗試鑄造到正確的對象類型? – 02strich 2012-03-27 11:45:38
嗨,只是打印集合對象不會幫助,你可以遍歷集合並打印個別對象的狀態 – Murugesh 2012-03-27 11:46:05
請提供一個代碼示例,顯示你正在嘗試做什麼。 – nwinkler 2012-03-27 11:47:01