2 count of Illegal Annotation Exception

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

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

Thanks for having a look!

share improve this question
 

1 Answer

up vote 9 down vote accepted

From the JavaDoc for @XmlType:

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.

share improve this answer
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值