0
讓我們假設我有以下XML:如何使用JAXB將元素上的屬性映射到POJO的內部屬性的字段?
<company name="Sun" country="Atlantis" state="Syracuse" city="Troy">
</company>
隨着JAXB,且無需使用第三方擴展,如的EclipseLink的@XmlPath
,有沒有辦法把它解組爲以下POJO結構:
@XmlRootElement
public class Company {
private String name;
private Address address;
// getters and setters
}
public class Address {
private String country;
private String state;
private String city;
// getters and setters
}
company.getAddress().getCountry(); // Atlantis