2012-04-10 73 views
8

我有一個客戶和CustomerFullAddress類和我使用JAXB,試圖產生一個XML文件2計數

<Customer CustomerID="GREAL"> 
    <CompanyName>Great Lakes Food Market</CompanyName> 
    <ContactName>Howard Snyder</ContactName> 
    <ContactTitle>Marketing Manager</ContactTitle> 
    <Phone>(503) 555-7555</Phone> 
    <FullAddress> 
     <Address>2732 Baker Blvd.</Address> 
     <City>Eugene</City> 
     <Region>OR</Region> 
     <PostalCode>97403</PostalCode> 
     <Country>USA</Country> 
    </FullAddress> 
</Customer> 

Customer類看起來像下面(它不是一個全面實施)

package org.abc.customers; 

import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlRootElement; 
import javax.xml.bind.annotation.XmlType; 

@XmlRootElement(name = "customer") 
@XmlType (propOrder = { "companyName", "contactName", "contactTitle", "phone" }) 

public class Customer { 

*@XmlElement(name = "customerfulladdress") 
private CustomerFullAddress custAdd;* 

private String companyName; 
private String contactName; 
private String contactTitle; 
private int phone; 

public CustomerFullAddress getCustAddress() { 
return custAdd; 
} 

public void setCustAddress(CustomerFullAddress custAdd) { 
this.custAdd = custAdd; 
} 
... 

雖然CustomerFullAddress是

package org.abc.customers; 

import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlRootElement; 
import javax.xml.bind.annotation.XmlType; 

@XmlRootElement(name = "customerfulladdress") 
//If you want you can define the order in which the fields are written 
//Optional 
@XmlType(propOrder = { "address", "city", "region", "postalCode", "country" }) 

public class CustomerFullAddress { 

private String address; 
... 

public String getAddress() { 
    return address; 
} 
public void setAddress(String address) { 
    this.address = address; 
} 
..... 
} 

且誤差

異常線程 「main」 com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException:IllegalAnnotationExceptions物業custAdd的2項 罪名是存在的,但XmlType.propOrder這個問題 沒有指定@有關 以下位置:在私人 org.abc.customers.CustomerFullAddress org.abc.customers.Customer.custAdd在 org.abc.customers.Customer物業custAddress存在,但在@ XmlType.propOrder這不是 規定問題與 以下位置有關:公開 org.abc.customers.Cus tomerFullAddress org.abc.customers.Customer.getCustAddress()在 org.abc.customers.Customer

感謝在看看!

回答

10

根據JavaDoc爲@XmlType

propOrder

所有JavaBean屬性被映射到必須列出XML模式元素。

您需要將CustomerFullAddress屬性添加到propOrderCustomer