2012-04-10 24 views
8

Ho un cliente e CustomerFullAddress di classe e sto usando JAXB per cercare di produrre un file XML2 conte di illegale annotazione Eccezione

<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> 

classe Customer appare come di seguito (La sua non è un'implementazione completa)

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

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

e l'errore è

Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 conti di IllegalAnnotationExceptions proprietà custAdd è presente ma non specificato nel @ XmlType.propOrder questo problema è relative al seguente percorso: a privato org.abc.customers.CustomerFullAddress org.abc.customers.Customer.custAdd a org.abc.customers.Customer Proprietà custAddress è presente ma non specificato nel @ XmlType.propOrder questo il problema è relativo al seguente luogo : al pubblico org.abc.customers.Cus tomerFullAddress org.abc.customers.Customer.getCustAddress() in org.abc.customers.Customer

Grazie per avere uno sguardo!

risposta

10

Dal JavaDoc per @XmlType:

propOrder

Tutte le proprietà JavaBean mappato ad elementi dello schema XML deve essere incluso.

è necessario aggiungere la proprietà CustomerFullAddress al propOrder per Customer.

Problemi correlati