java 2 次非法注释异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10094622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 23:35:48  来源:igfitidea点击:

2 count of Illegal Annotation Exception

javaxmljaxb

提问by mu_sa

I have a Customer and CustomerFullAddress class and i am using JAXB to try to produce an XML file

我有一个 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>

The Customer Class looks like below (Its not a full implementation)

客户类如下所示(它不是一个完整的实现)

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;
}
...

While the CustomerFullAddress is

虽然 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;
}
.....
 }

and the error is

错误是

Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions Property custAdd is present but not specified in @XmlType.propOrder this problem is related to the following location: at private org.abc.customers.CustomerFullAddress org.abc.customers.Customer.custAdd at org.abc.customers.Customer Property custAddress is present but not specified in @XmlType.propOrder this problem is related to the following location: at public org.abc.customers.CustomerFullAddress org.abc.customers.Customer.getCustAddress() at org.abc.customers.Customer

线程“main”com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException 中的异常:存在 2 个 IllegalAnnotationExceptions 属性 custAdd 计数但未在 @XmlType.propOrder 中指定此问题与以下位置有关:在私人组织.abc.customers.CustomerFullAddress org.abc.customers.Customer.custAdd 在 org.abc.customers.Customer 属性 custAddress 存在但未在 @XmlType.propOrder 中指定此问题与以下位置有关:在公共 org.abc。 customer.CustomerFullAddress org.abc.customers.Customer.getCustAddress() 在 org.abc.customers.Customer

Thanks for having a look!

感谢您的观看!

回答by darrengorman

From the JavaDoc for @XmlType:

来自@XmlType的 JavaDoc :

propOrder

All of the JavaBean properties being mapped to XML Schema elements must be listed.

订单

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

You need to add the CustomerFullAddressproperty to the propOrderfor Customer.

您需要将该CustomerFullAddress属性添加到propOrderfor Customer