我很难将xml元素的集合映射到java对象列表。应该有一些不同的内容值,但输出显示每个元素0
。
更新:我使用自定义网络服务测试了相同的代码。它工作正常。
这是我的更新xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<users>
<user>
<id>1</id>
<name>James</name>
<profession>teacher</profession>
</user>
<user>
<id>2</id>
<name>Kelly</name>
<profession>teacher</profession>
</user>
</users>`
这是早期的xml代码:
//XML
<CUSTOMERList xmlns:xlink="http://www.w3.org/1999/xlink">
<CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/">0</CUSTOMER>
<CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/1/">1</CUSTOMER>
<CUSTOMER xlink:href="http://www.thomas-bayer.com/sqlrest/CUSTOMER/6/">6</CUSTOMER>
:
:
这是CustomerList
类:
//Customerlist POJO
@XmlRootElement(name = "CUSTOMER")
public class CustomerList {
private int CUSTOMER;
public int getCUSTOMER() {
return CUSTOMER;
}
public void setCUSTOMER(int cUSTOMER) {
CUSTOMER = cUSTOMER;
}
}
// Jersey Client
Client client = Client.create();
URI uri = new URI("http://www.thomas-bayer.com/sqlrest/CUSTOMER/");
WebResource webResource = client.resource(uri);
List<CustomerList> customers = webResource.path("").accept(MediaType.APPLICATION_XML_TYPE).get(new GenericType<List<CustomerList>>(){});
for(CustomerList c : customers){
System.out.println("### " + c.getCUSTOMER() );
}
提前感谢您的帮助。