您好,欢迎来到年旅网。
搜索
您的当前位置:首页2 count of Illegal Annotation Exception

2 count of Illegal Annotation Exception

来源:年旅网

7

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

<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

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

Thanks for having a look!

 

1 Answer

9 accepted

From the JavaDoc for :

propOrder

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

You need to add the CustomerFullAddress property to the propOrder for Customer.

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务