2个非法注释例外计数

时间:2012-04-10 18:48:08

标签: java xml jaxb

我有一个Customer和CustomerFullAddress类,我正在使用JAXB来尝试生成XML文件

<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 Class如下所示(它不是完整的实现)

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:2   IllegalAnnotationExceptions的计数属性custAdd存在但是   未在@ XmlType.propOrder中指定此问题与   以下位置:私人   org.abc.customers.CustomerFullAddress   org.abc.customers.Customer.custAdd at   org.abc.customers.Customer属性custAddress存在但不存在   在@ XmlType.propOrder中指定此问题与   以下地点:公开场合   org.abc.customers.CustomerFullAddress   org.abc.customers.Customer.getCustAddress()at   org.abc.customers.Customer

感谢您一看!

1 个答案:

答案 0 :(得分:11)

来自@XmlType的JavaDoc:

  

<强> propOrder

     

必须列出所有映射到XML Schema元素的JavaBean属性。

您需要将CustomerFullAddress属性添加到propOrder的{​​{1}}。

相关问题