【发布时间】:2012-08-23 23:04:34
【问题描述】:
我正在尝试在客户端解组 JAXB,但我得到 对象的属性 NULL。
这就是我正在做的解组
URL url = new URL("http://localhost:9191/service/firstName/tony?format=xml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/atom+xml");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
JAXBContext jaxbContext = JAXBContext.newInstance(LDAPUsers.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
LDAPUsers lu = (LDAPUsers) jaxbUnmarshaller.unmarshal(br);
ArrayList<LDAPUser> list = new ArrayList<LDAPUser>();
//list.addAll(lu.getCounty());
**System.out.println(lu.ldapUser.get(0).getFirstName());//this is giving NULL**
conn.disconnect();
请帮忙!!!
【问题讨论】:
-
调试并在列表中使用断点,检查该列表不为空且对象已设置所有属性。
-
它没有击中二传手...
-
您的 XML 和域对象是什么样的?