当前位置: 首页 > 知识库问答 >
问题:

JAXB非法注释例外

叶鹭洋
2023-03-14

我第一次与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

.. 等

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)

我尝试了不同的@xmlacessortype。。。但是没有变化。我还尝试过用@xmltransive注释这些方法,但没有区别。我做错了什么?

共有1个答案

微生毅
2023-03-14

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

  • http://blog.bdoughan.com/2012/02/jaxbs-xmltype-and-proporder.html

此外,如果要注释字段,则应指定@XmlAccessorType(XmlAccessType。字段)在你的类上。

  • http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html

另外,因为我注意到您的模型中有继承,所以您不能将继承的属性包含在proorder中,除非您用@Xml瞬态标记部件类。

  • http://blog.bdoughan.com/2012/08/jaxbs-xmltransient-and-property-order.html
 类似资料:
  • 我一直在使用Metro,遇到了一个问题,wsgen似乎忽略了我在web方法响应类上添加的任何JAXB注释。 我试图返回一组实体类,我想通过网络服务向外部客户端公开,但是我只想让某些类属性和方法对外部客户端可见,所以将类存取类型设置为PROPERTY,并进行注释所有属性我想成为@XmlElement类的XML版本的一部分。 我可以使用schemagen ant任务为实体类创建XML模式,该任务正确地

  • 我在这里使用教程来理解JAXB。 当编写器开始创建文档的根时,编写器开始如下: 尽管我将手动生成我的类,而不是让Eclipse来完成,但我将为我的jar文件提供一个(不是打包在里面,而是打包在包含jar文件的文件夹中),以便当我的应用程序启动时,它将验证XML文档是否已被篡改。 因此,在XSD文件中,targetNamespace将是de.vogella。xml。jaxb。模型,因为它在上面被声明

  • 问题内容: 我有一个要求,根据字段上标记的自定义注释来编组/解组java pojo的某些元素。假设我的Java pojp中有3个字段 如果我在jaxb中进行转换时传递version =“ v1”参数,我只想编组具有v1的字段。如果我通过v2,则所有带v2注释的字段都应编组。 甚至可以使用jaxb吗?我确信选择性的编组将通过某种图书馆或某种方式得到支持,经过大量的搜索后仍无法弄清楚。任何帮助或建议或

  • 手工编写类和从scheme生成JAXB类的优缺点是什么。我开始新的项目,并希望了解如何选择避免陷阱。 我有复杂的XML结构(基本上是FreeSwitch配置定义),包括不同XML级别上的可重复类型。

  • 考虑到JAXB注释的对象,是否有办法确定类/字段/方法在封送过程中是否会导致xsi: type? 是XmlElement注释, 我唯一需要担心的情况? 我正在编写一个Lua解组器,在这里我们删除了很多常见的xml类型信息,我正在尝试找出如何将传入的Lua与JAXB匹配。 谢谢 --更新-- 下面是一个简单的示例,说明了问题: 当我收到一个动物对象时,我可以查询动物的注释来检测它应该是狗或猫而不是动

  • 我在一个jaxb注释类中有一个方法,当且仅当它使用jersey 1.16编组到JSON时,我想编组一个值,它在下面使用jackson 1.9。我希望使用jaxb的@XmlTransient和jackson的@JsonProperty以这样的方式完成这项工作: …但马歇尔似乎一点也不觉得。没有遇到错误。