10

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>

カスタマークラスは次のようになります(完全な実装ではありません)

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に指定されていませんこの問題は、次の場所に関連しています:プライベート組織.abc.customers.CustomerFullAddress org.abc.customers.Customer.custAdd at org.abc.customers.CustomerプロパティcustAddressは存在しますが、@ XmlType.propOrderに指定されていません。この問題は、次の場所に関連しています:atpublicorg.abc。 Customers.CustomerFullAddress org.abc.customers.Customer.getCustAddress()(org.abc.customers.Customer)

ご覧いただきありがとうございます!

4

1 に答える 1

13

@XmlTypeのJavaDocから:

propOrder

XMLスキーマ要素にマップされているすべてのJavaBeanプロパティをリストする必要があります。

forにCustomerFullAddressプロパティを追加する必要があります。propOrderCustomer

于 2012-04-10T18:59:08.570 に答える