1
를 비 정렬 한 후 빈 목록을 반환은 다음과 같습니다 : 나는 목록을 언 마샬링하려고하지만 목록이 항상 비어, 나는 REST에서 반환 된 XML이 XML
<customers>
<customer>
<addressline1>111 E. Las Olas Blvd</addressline1>
<addressline2>Suite 51</addressline2>
<city>Fort Lauderdale</city>
<creditLimit>100000</creditLimit>
<customerId>1</customerId>
<discountCode>
<discountCode>56</discountCode>
<rate>0.00</rate>
</discountCode>
<email>[email protected]</email>
<fax>305-777-4635</fax>
<name>Kupa</name>
<phone>305-777-4632</phone>
<state>FL</state>
<zip>
<areaLength>22.0</areaLength>
<areaWidth>23.0</areaWidth>
<radius>50.0</radius>
<zipCode>90-200</zipCode>
</zip>
</customer>
</customers>
. 어쩌면 고객 클래스에서 Zip 및 DiscountCode가 다른 엔티티이므로 XML로만 문자열을 가질 수 있으며 엔티티를 만들 수 없습니다.
이
내 자바 클래스입니다 :@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Customers
{
@XmlElement
private List<Customer> customers = new ArrayList<Customer>();
public List<Customer> getCustomers()
{
return customers;
}
}
@Entity
@Table(name = "customer")
@XmlRootElement(name = "customer")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "customer_id")
private Integer customerId;
@Column(name = "name")
private String name;
@Column(name = "addressline1")
private String addressline1;
@Column(name = "addressline2")
private String addressline2;
@Column(name = "city")
private String city;
@Column(name = "state")
private String state;
@Column(name = "phone")
private String phone;
@Column(name = "fax")
private String fax;
@Column(name = "email")
private String email;
@Column(name = "credit_limit")
private Integer creditLimit;
@JoinColumn(name = "discount_code", referencedColumnName = "discount_code")
@ManyToOne(optional = false)
private DiscountCode discountCode;
@JoinColumn(name = "zip", referencedColumnName = "zip_code")
@ManyToOne(optional = false)
private MicroMarket zip;
// later only setters and getters
}
그리고 이것은 내가 비 정렬하고있는 방법입니다
JAXBContext context = JAXBContext.newInstance(Customers.class, Customer.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
Customers customers = (Customers) unmarshaller.unmarshal(new StringReader(allXmlString));
나는 유사한 주제를 봐 왔지만, 그 중 하나는 저를 도왔다. 언 마샬링 후 내 목록이 항상 비어있는 이유는 무엇입니까?
도움 주셔서 감사합니다.