JAXB IllegalAnnotationExceptions

时间:2013-09-21 20:48:58

标签: java xml jaxb

我是第一次与JAXB合作,并且在理解它希望我做什么方面遇到了一些问题。

我已经设置了一个类,它将成为一个相当大的XML的一部分 - 这个类将代表XML文档的“Header”部分。

package com.somecompany.jscentral.xml.integrator.soc;

import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import com.somecompany.jscentral.xml.AbstractXML;

@XmlRootElement(name = "Header")
@XmlAccessorType(XmlAccessType.NONE)
@XmlType(propOrder = {"OrderRoutine", "CreationDate", "CreationTime", "UserId", "CustomerNumber", 
                        "OrderType", "Salesman", "Handler", "Warehouse", "PrimaryCurrency", "OrderNumber", 
                        "Name", "OrderDate", "DeliveryAddressNumber", "ConfirmationAddressNumber", "FullName999", 
                        "CompanyName999", "StreetAddress999Line1", "StreetAddress999Line2", "City999", "StateProvince999", 
                        "PostCode999", "Country999", "Resale999", "InvoiceCustomerNumber", "CustomerReference", 
                        "NumberOfInvoiceCopies", "Language", "VAT", "Backlog", "OrderDiscountPercent", "DiscountGroup", 
                        "PriceCode", "StandardTextNumber", "HoldOrder", "TermsOfPayment", "CreditDays", "TermsOfDelivery", 
                        "MannerOfTransport", "FreightFee", "PostageFee", "InsuranceFee", "AdministrationFee", "InvoiceFee", 
                        "CustomersOrderNumberReference", "GoodsMarking", "HoldInvoice", "DeliveryAddressEngineer", 
                        "DeliveryAddressLocation", "CountryDispatchedToArrivedFrom", "VATRegNumberOfDebtorAddr", 
                        "NatureOfTransaction", "VATHandlingCode", "PortOfArrivalDispatch", "CountryOfTrader", "InternalOrder", 
                        "ToWarehouse", "RouteId", "DepartureId", "DestinationId", "ShippingAgent", "ContactListCode", 
                        "Salesman2", "CreationDate2", "Sequence", "DebtorNumber", "DebtorAddressNumber", "InvoiceAddressNumber", 
                        "WebOrder", "Confirmed", "ClientIdentity"})
public class Header extends AbstractXML {

    public Header() throws JAXBException {

        super();

    }

    @XmlElement(name = "OrderRoutine", required = true)
    private String orderRoutine;

    public void setOrderRoutine(String orderRoutine) {

        this.orderRoutine = orderRoutine;

    }

    public String getOrderRoutine() {

        return this.orderRoutine;

    }

    @XmlElement(name = "CreationDate", required = false)
    private String creationDate;

    public void setCreationDate(String creationDate) {

        this.creationDate = creationDate;

    }

    public String getCreationDate() {

        return this.creationDate;

    }

    @XmlElement(name = "CreationTime", required = false)
    private String creationTime;

    public void setCreationTime(String creationTime) {

        this.creationTime = creationTime;

    }

    public String getCreationTime() {

        return this.creationTime;

    }

    @XmlElement(name = "UserId", required = false)
    private String userId;

    public void setUserId(String userId) {

        this.userId = userId;

    }

    public String getUserId() {

        return this.userId;

    }

    @XmlElement(name = "CustomerNumber", required = true)
    private String customerNumber;

    public void setCustomerNumber(String customerNumber) {

        this.customerNumber = customerNumber;

    }

    public String getCustomerNumber() {

        return this.customerNumber;

    }

    @XmlElement(name = "OrderType", required = true)
    private String orderType;

    public void setOrderType(String orderType) {

        this.orderType = orderType;

    }

    public String getOrderType() {

        return this.orderType;

    }

    @XmlElement(name = "Salesman", required = true)
    private String salesman;

    public void setSalesman(String salesman) {

        this.salesman = salesman;

    }

    public String getSalesman() {

        return this.salesman;

    }

    @XmlElement(name = "Handler", required = true)
    private String handler;

    public void setHandler(String handler) {

        this.handler = handler;

    }

    public String getHandler() {

        return this.handler;

    }

    @XmlElement(name = "Warehouse", required = true)
    private String warehouse;

    public void setWarehouse(String warehouse) {

        this.warehouse = warehouse;

    }

    public String getWarehouse() {

        return this.warehouse;

    }

    @XmlElement(name = "PrimaryCurrency", required = true)
    private String primaryCurrency;

    public void setPrimaryCurrency(String primaryCurrency) {

        this.primaryCurrency = primaryCurrency;

    }

    public String getPrimaryCurrency() {

        return this.primaryCurrency;

    }

    @XmlElement(name = "OrderNumber", required = false)
    private String orderNumber;

    public void setOrderNumber(String orderNumber) {

        this.orderNumber = orderNumber;

    }

    public String getOrderNumber() {

        return this.orderNumber;

    }

    @XmlElement(name = "Name", required = false)
    private String name;

    public void setName(String name) {

        this.name = name;

    }

    public String getName() {

        return this.name;

    }

    @XmlElement(name = "OrderDate", required = false)
    private String orderDate;

    public void setOrderDate(String orderDate) {

        this.orderDate = orderDate;

    }

    public String getOrderDate() {

        return this.orderDate;

    }

    @XmlElement(name = "DeliveryAddressNumber", required = false)
    private String deliveryAddressNumber;

    public void setDeliveryAddressNumber(String deliveryAddressNumber) {

        this.deliveryAddressNumber = deliveryAddressNumber;

    }

    public String getDeliveryAddressNumber() {

        return this.deliveryAddressNumber;

    }

    @XmlElement(name = "ConfirmationAddressNumber", required = false)
    private String confirmationAddressNumber;

    public void setConfirmationAddressNumber(String confirmationAddressNumber) {

        this.confirmationAddressNumber = confirmationAddressNumber;

    }

    public String getConfirmationAddressNumber() {

        return this.confirmationAddressNumber;

    }

    @XmlElement(name = "FullName999", required = true)
    private String fullName999;

    public void setFullName999(String fullName999) {

        this.fullName999 = fullName999;

    }

    public String getFullName999() {

        return this.fullName999;

    }

    @XmlElement(name = "CompanyName999", required = true)
    private String companyName999;

    public void setCompanyName999(String companyName999) {

        this.companyName999 = companyName999;

    }

    public String getCompanyName999() {

        return this.companyName999;

    }

    @XmlElement(name = "StreetAddress999Line1", required = true)
    private String streetAddress999Line1;

    public void setStreetAddress999Line1(String streetAddress999Line1) {

        this.streetAddress999Line1 = streetAddress999Line1;

    }

    public String getStreetAddress999Line1() {

        return this.streetAddress999Line1;

    }

    @XmlElement(name = "StreetAddress999Line2", required = true)
    private String streetAddress999Line2;

    public void setStreetAddress999Line2(String streetAddress999Line2) {

        this.streetAddress999Line2 = streetAddress999Line2;

    }

    public String getStreetAddress999Line2() {

        return this.streetAddress999Line2;

    }

    @XmlElement(name = "City999", required = true)
    private String city999;

    public void setCity999(String city999) {

        this.city999 = city999;

    }

    public String getCity999() {

        return this.city999;

    }

    @XmlElement(name = "StateProvince999", required = true)
    private String stateProvince999;

    public void setStateProvince999(String stateProvince999) {

        this.stateProvince999 = stateProvince999;

    }

    public String getStateProvince999() {

        return this.stateProvince999;

    }

    @XmlElement(name = "PostCode999", required = true)
    private String postCode999;

    public void setPostCode999(String postCode999) {

        this.postCode999 = postCode999;

    }

    public String getPostCode999() {

        return this.postCode999;

    }

    @XmlElement(name = "Country999", required = true)
    private String country999;

    public void setCountry999(String country999) {

        this.country999 = country999;

    }

    public String getCountry999() {

        return this.country999;

    }

    @XmlElement(name = "Resale999", required = false)
    private String resale999;

    public void setResale999(String resale999) {

        this.resale999 = resale999;

    }

    public String getResale999() {

        return this.resale999;

    }

    @XmlElement(name = "InvoiceCustomerNumber", required = false)
    private String invoiceCustomerNumber;

    public void setInvoiceCustomerNumber(String invoiceCustomerNumber) {

        this.invoiceCustomerNumber = invoiceCustomerNumber;

    }

    public String getInvoiceCustomerNumber() {

        return this.invoiceCustomerNumber;

    }

    @XmlElement(name = "CustomerReference", required = false)
    private String customerReference;

    public void setCustomerReference(String customerReference) {

        this.customerReference = customerReference;

    }

    public String getCustomerReference() {

        return this.customerReference;

    }

    @XmlElement(name = "NumberOfInvoiceCopies", required = false)
    private String numberOfInvoiceCopies;

    public void setNumberOfInvoiceCopies(String numberOfInvoiceCopies) {

        this.numberOfInvoiceCopies = numberOfInvoiceCopies;

    }

    public String getNumberOfInvoiceCopies() {

        return this.numberOfInvoiceCopies;

    }

    @XmlElement(name = "Language", required = false)
    private String language;

    public void setLanguage(String language) {

        this.language = language;

    }

    public String getLanguage() {

        return this.language;

    }

    @XmlElement(name = "VAT", required = false)
    private String vat;

    public void setVAT(String vat) {

        this.vat = vat;

    }

    public String getVAT() {

        return this.vat;

    }

    @XmlElement(name = "Backlog", required = false)
    private String backlog;

    public void setBacklog(String backlog) {

        this.backlog = backlog;

    }

    public String getBacklog() {

        return this.backlog;

    }

    @XmlElement(name = "OrderDiscountPercent", required = false)
    private String orderDiscountPercent;

    public void setOrderDiscountPercent(String orderDiscountPercent) {

        this.orderDiscountPercent = orderDiscountPercent;

    }

    public String getOrderDiscountPercent() {

        return this.orderDiscountPercent;

    }

    @XmlElement(name = "DiscountGroup", required = false)
    private String discountGroup;

    public void setDiscountGroup(String discountGroup) {

        this.discountGroup = discountGroup;

    }

    public String getDiscountGroup() {

        return this.discountGroup;

    }

    @XmlElement(name = "PriceCode", required = false)
    private String priceCode;

    public void setPriceCode(String priceCode) {

        this.priceCode = priceCode;

    }

    public String getPriceCode() {

        return this.priceCode;

    }

    @XmlElement(name = "StandardTextNumber", required = false)
    private String standardTextNumber;

    public void setStandardTextNumber(String standardTextNumber) {

        this.standardTextNumber = standardTextNumber;

    }

    public String getStandardTextNumber() {

        return this.standardTextNumber;

    }

    @XmlElement(name = "HoldOrder", required = false)
    private String holdOrder;

    public void setHoldOrder(String holdOrder) {

        this.holdOrder = holdOrder;

    }

    public String getHoldOrder() {

        return this.holdOrder;

    }

    @XmlElement(name = "TermsOfPayment", required = true)
    private String termsOfPayment;

    public void setTermsOfPayment(String termsOfPayment) {

        this.termsOfPayment = termsOfPayment;

    }

    public String getTermsOfPayment() {

        return this.termsOfPayment;

    }

    @XmlElement(name = "CreditDays", required = false)
    private String creditDays;

    public void setCreditDays(String creditDays) {

        this.creditDays = creditDays;

    }

    public String getCreditDays() {

        return this.creditDays;

    }

    @XmlElement(name = "TermsOfDelivery", required = false)
    private String termsOfDelivery;

    public void setTermsOfDelivery(String termsOfDelivery) {

        this.termsOfDelivery = termsOfDelivery;

    }

    public String getTermsOfDelivery() {

        return this.termsOfDelivery;

    }

    @XmlElement(name = "MannerOfTransport", required = true)
    private String mannerOfTransport;

    public void setMannerOfTransport(String mannerOfTransport) {

        this.mannerOfTransport = mannerOfTransport;

    }

    public String getMannerOfTransport() {

        return this.mannerOfTransport;

    }

    @XmlElement(name = "FreightFee", required = true)
    private String freightFee;

    public void setFreightFee(String freightFee) {

        this.freightFee = freightFee;

    }

    public String getFreightFee() {

        return this.freightFee;

    }

    @XmlElement(name = "PostageFee", required = false)
    private String postageFee;

    public void setPostageFee(String postageFee) {

        this.postageFee = postageFee;

    }

    public String getPostageFee() {

        return this.postageFee;

    }

    @XmlElement(name = "InsuranceFee", required = false)
    private String insuranceFee;

    public void setInsuranceFee(String insuranceFee) {

        this.insuranceFee = insuranceFee;

    }

    public String getInsuranceFee() {

        return this.insuranceFee;

    }

    @XmlElement(name = "AdministrationFee", required = false)
    private String administrationFee;

    public void setAdministrationFee(String administrationFee) {

        this.administrationFee = administrationFee;

    }

    public String getAdministrationFee() {

        return this.administrationFee;

    }

    @XmlElement(name = "InvoiceFee", required = false)
    private String invoiceFee;

    public void setInvoiceFee(String invoiceFee) {

        this.invoiceFee = invoiceFee;

    }

    public String getInvoiceFee() {

        return this.invoiceFee;

    }

    @XmlElement(name = "CustomersOrderNumberReference", required = true)
    private String customersOrderNumberReference;

    public void setCustomersOrderNumberReference(String customersOrderNumberReference) {

        this.customersOrderNumberReference = customersOrderNumberReference;

    }

    public String getCustomersOrderNumberReference() {

        return this.customersOrderNumberReference;

    }

    @XmlElement(name = "GoodsMarking", required = true)
    private String goodsMarking;

    public void setGoodsMarking(String goodsMarking) {

        this.goodsMarking = goodsMarking;

    }

    public String getGoodsMarking() {

        return this.goodsMarking;

    }

    @XmlElement(name = "HoldInvoice", required = false)
    private String holdInvoice;

    public void setcustomersOrderNumberReference(String holdInvoice) {

        this.holdInvoice = holdInvoice;

    }

    public String getcustomersOrderNumberReference() {

        return this.holdInvoice;

    }

    @XmlElement(name = "DeliveryAddressEngineer", required = false)
    private String deliveryAddressEngineer;

    public void setDeliveryAddressEngineer(String deliveryAddressEngineer) {

        this.deliveryAddressEngineer = deliveryAddressEngineer;

    }

    public String getDeliveryAddressEngineer() {

        return this.deliveryAddressEngineer;

    }

    @XmlElement(name = "DeliveryAddressLocation", required = false)
    private String deliveryAddressLocation;

    public void setDeliveryAddressLocation(String deliveryAddressLocation) {

        this.deliveryAddressLocation = deliveryAddressLocation;

    }

    public String getDeliveryAddressLocation() {

        return this.deliveryAddressLocation;

    }

    @XmlElement(name = "CountryDispatchedToArrivedFrom", required = false)
    private String countryDispatchedToArrivedFrom;

    public void setCountryDispatchedToArrivedFrom(String countryDispatchedToArrivedFrom) {

        this.countryDispatchedToArrivedFrom = countryDispatchedToArrivedFrom;

    }

    public String getCountryDispatchedToArrivedFrom() {

        return this.countryDispatchedToArrivedFrom;

    }

    @XmlElement(name = "VATRegNumberOfDebtorAddr", required = false)
    private String vatRegNumberOfDebtorAddr;

    public void setVATRegNumberOfDebtorAddr(String vatRegNumberOfDebtorAddr) {

        this.vatRegNumberOfDebtorAddr = vatRegNumberOfDebtorAddr;

    }

    public String getVATRegNumberOfDebtorAddr() {

        return this.vatRegNumberOfDebtorAddr;

    }

    @XmlElement(name = "NatureOfTransaction", required = false)
    private String natureOfTransaction;

    public void setNatureOfTransaction(String natureOfTransaction) {

        this.natureOfTransaction = natureOfTransaction;

    }

    public String getNatureOfTransaction() {

        return this.natureOfTransaction;

    }

    @XmlElement(name = "VATHandlingCode", required = false)
    private String vatHandlingCode;

    public void setVATHandlingCode(String vatHandlingCode) {

        this.vatHandlingCode = vatHandlingCode;

    }

    public String getVATHandlingCode() {

        return this.vatHandlingCode;

    }

    @XmlElement(name = "PortOfArrivalDispatch", required = false)
    private String portOfArrivalDispatch;

    public void setPortOfArrivalDispatch(String portOfArrivalDispatch) {

        this.portOfArrivalDispatch = portOfArrivalDispatch;

    }

    public String getPortOfArrivalDispatch() {

        return this.portOfArrivalDispatch;

    }

    @XmlElement(name = "CountryOfTrader", required = false)
    private String countryOfTrader;

    public void setCountryOfTrader(String countryOfTrader) {

        this.countryOfTrader = countryOfTrader;

    }

    public String getCountryOfTrader() {

        return this.countryOfTrader;

    }

     // ETC... 

}

这是堆栈跟踪:

Exception in thread "main" com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 142 counts of IllegalAnnotationExceptions
Property orderRoutine is present but not specified in @XmlType.propOrder
    this problem is related to the following location:
        at private java.lang.String com.somecompany.jscentral.xml.integrator.soc.Header.orderRoutine
        at com.somecompany.jscentral.xml.integrator.soc.Header
Property creationDate is present but not specified in @XmlType.propOrder
    this problem is related to the following location:
        at private java.lang.String com.somecompany.jscentral.xml.integrator.soc.Header.creationDate
        at com.somecompany.jscentral.xml.integrator.soc.Header
Property creationTime is present but not specified in @XmlType.propOrder
    this problem is related to the following location:
        at private java.lang.String com.somecompany.jscentral.xml.integrator.soc.Header.creationTime
        at com.somecompany.jscentral.xml.integrator.soc.Header
Property userId is present but not specified in @XmlType.propOrder
    this problem is related to the following location:
        at private java.lang.String com.somecompany.jscentral.xml.integrator.soc.Header.userId
        at com.somecompany.jscentral.xml.integrator.soc.Header

.. ETC ..

Property OrderRoutine appears in @XmlType.propOrder, but no such property exists. Maybe you meant orderRoutine?
    this problem is related to the following location:
        at com.somecompany.jscentral.xml.integrator.soc.Header
Property CreationDate appears in @XmlType.propOrder, but no such property exists. Maybe you meant creationDate?
    this problem is related to the following location:
        at com.somecompany.jscentral.xml.integrator.soc.Header
Property CreationTime appears in @XmlType.propOrder, but no such property exists. Maybe you meant creationTime?
    this problem is related to the following location:
        at com.somecompany.jscentral.xml.integrator.soc.Header

.. ETC .. 

Property InvoiceAddressNumber appears in @XmlType.propOrder, but no such property exists. Maybe you meant invoiceAddressNumber?
    this problem is related to the following location:
        at com.somecompany.jscentral.xml.integrator.soc.Header
Property WebOrder appears in @XmlType.propOrder, but no such property exists. Maybe you meant webOrder?
    this problem is related to the following location:
        at com.somecompany.jscentral.xml.integrator.soc.Header
Property Confirmed appears in @XmlType.propOrder, but no such property exists. Maybe you meant confirmed?
    this problem is related to the following location:
        at com.somecompany.jscentral.xml.integrator.soc.Header
Property ClientIdentity appears in @XmlType.propOrder, but no such property exists. Maybe you meant clientIdentity?
    this problem is related to the following location:
        at com.somecompany.jscentral.xml.integrator.soc.Header

    at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(Unknown Source)
    at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(Unknown Source)
    at com.sun.xml.internal.bind.v2.ContextFactory.createContext(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.newInstance(Unknown Source)
    at javax.xml.bind.ContextFinder.find(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at javax.xml.bind.JAXBContext.newInstance(Unknown Source)
    at com.somecompany.jscentral.xml.AbstractXML.<init>(AbstractXML.java:21)
    at com.somecompany.jscentral.xml.integrator.soc.Header.<init>(Header.java:33)
    at com.somecompany.jscentral.xml.integrator.IntegratorSOCXML.main(IntegratorSOCXML.java:22)

我尝试了不同的@XmlAccessorType ...但没有变化。我也尝试用@XmlTransient注释方法,没有区别。我究竟做错了什么?

1 个答案:

答案 0 :(得分:16)

propOrder基于字段/属性名称而不是元素名称。如果您进行此更改,一切都将正常工作。

此外,如果您要对字段进行注释,则应在课程中指定@XmlAccessorType(XmlAccessType.FIELD)

此外,由于我注意到您的模型中有继承,因此除非您使用propOrder标记零件类,否则不能在@XmlTransient中包含继承的属性。