Unmarshalling Error: unexpected element (uri:url, local:“objectname”). Expected elements are <{}objectname>

后端 未结 5 1434
梦谈多话
梦谈多话 2021-02-14 19:33

I\'m using jaxb2-marshaller to generate classes to communicate with a webservice. Java-classes are generated with use of some wsdl files.

Everything is okay now, but whe

5条回答
  •  醉酒成梦
    2021-02-14 19:38

    Please use the following annotation

    @XmlRootElement(name="Customer")
    

    at the root of the class as shown below. Since JAXb wont create @XmlRootElement annotation automatically, you need to manually put this annotation at the top of the class.

     The generated ObjectFactory class:
    This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.7 
    // See http://java.sun.com/xml/jaxb 
    // Any modifications to this file will be lost upon recompilation of the source schema. 
    // Generated on: 2014.09.12 at 12:04:04 PM CEST 
    //
    
    
    package einvoice.proxy.customerdaoservice;
    
    import javax.xml.bind.JAXBElement;
    import javax.xml.bind.annotation.XmlElementDecl;
    import javax.xml.bind.annotation.XmlRegistry;
    import javax.xml.namespace.QName;
    
    
    /**
     * This object contains factory methods for each 
     * Java content interface and Java element interface 
     * generated in the be.icredit.einvoice.proxy.customerdaoservice package. 
     * 

    An ObjectFactory allows you to programatically * construct new instances of the Java representation * for XML content. The Java representation of XML * content can consist of schema derived interfaces * and classes representing the binding of schema * type definitions, element declarations and model * groups. Factory methods for each of these are * provided in this class. * */ @XmlRootElement(name="Customer") @XmlRegistry public class ObjectFactory { private final static QName _AbstractFilter_QNAME = new QName("http://xxxxxxx/", "abstractFilter"); private final static QName _Customer_QNAME = new QName("http://xxxxxxx/", "customer"); private final static QName _FindSingleResponse_QNAME = new QName("http://xxxxxxx/", "findSingleResponse"); private final static QName _Create_QNAME = new QName("http://xxxxxxx/", "create"); private final static QName _Find_QNAME = new QName("http://xxxxxxx/", "find"); private final static QName _CreateResponse_QNAME = new QName("xxxxxxx/", "createResponse"); private final static QName _FindResponse_QNAME = new QName("http://xxxxxxx/", "findResponse"); private final static QName _UpdateResponse_QNAME = new QName("http://xxxxxxx/", "updateResponse"); private final static QName _FindSingle_QNAME = new QName("http://xxxxxxx/", "findSingle"); private final static QName _CustomerFilter_QNAME = new QName("http://xxxxxxx/", "customerFilter"); private final static QName _Update_QNAME = new QName("http://xxxxxxx/", "update"); private final static QName _AbstractEntity_QNAME = new QName("http://xxxxxxx/", "abstractEntity"); /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: be.icredit.einvoice.proxy.customerdaoservice * */ public ObjectFactory() { } /** * Create an instance of {@link Update } * */ public Update createUpdate() { return new Update(); } /** * Create an instance of {@link CustomerFilter } * */ public CustomerFilter createCustomerFilter() { return new CustomerFilter(); } /** * Create an instance of {@link UpdateResponse } * */ public UpdateResponse createUpdateResponse() { return new UpdateResponse(); } /** * Create an instance of {@link FindSingle } * */ public FindSingle createFindSingle() { return new FindSingle(); } /** * Create an instance of {@link FindResponse } * */ public FindResponse createFindResponse() { return new FindResponse(); } /** * Create an instance of {@link CreateResponse } * */ public CreateResponse createCreateResponse() { return new CreateResponse(); } /** * Create an instance of {@link FindSingleResponse } * */ public FindSingleResponse createFindSingleResponse() { return new FindSingleResponse(); } /** * Create an instance of {@link Customer } * */ public Customer createCustomer() { return new Customer(); } /** * Create an instance of {@link Create } * */ public Create createCreate() { return new Create(); } /** * Create an instance of {@link Find } * */ public Find createFind() { return new Find(); } /** * Create an instance of {@link Pager } * */ public Pager createPager() { return new Pager(); } /** * Create an instance of {@link JAXBElement }{@code <}{@link AbstractFilter }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "abstractFilter") public JAXBElement createAbstractFilter(AbstractFilter value) { return new JAXBElement(_AbstractFilter_QNAME, AbstractFilter.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link Customer }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "customer") public JAXBElement createCustomer(Customer value) { return new JAXBElement(_Customer_QNAME, Customer.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link FindSingleResponse }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "findSingleResponse") public JAXBElement createFindSingleResponse(FindSingleResponse value) { return new JAXBElement(_FindSingleResponse_QNAME, FindSingleResponse.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link Create }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "create") public JAXBElement createCreate(Create value) { return new JAXBElement(_Create_QNAME, Create.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link Find }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "find") public JAXBElement createFind(Find value) { return new JAXBElement(_Find_QNAME, Find.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link CreateResponse }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "createResponse") public JAXBElement createCreateResponse(CreateResponse value) { return new JAXBElement(_CreateResponse_QNAME, CreateResponse.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link FindResponse }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "findResponse") public JAXBElement createFindResponse(FindResponse value) { return new JAXBElement(_FindResponse_QNAME, FindResponse.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link UpdateResponse }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "updateResponse") public JAXBElement createUpdateResponse(UpdateResponse value) { return new JAXBElement(_UpdateResponse_QNAME, UpdateResponse.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link FindSingle }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "findSingle") public JAXBElement createFindSingle(FindSingle value) { return new JAXBElement(_FindSingle_QNAME, FindSingle.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link CustomerFilter }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "customerFilter") public JAXBElement createCustomerFilter(CustomerFilter value) { return new JAXBElement(_CustomerFilter_QNAME, CustomerFilter.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link Update }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "update") public JAXBElement createUpdate(Update value) { return new JAXBElement(_Update_QNAME, Update.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link AbstractEntity }{@code >}} * */ @XmlElementDecl(namespace = "http://xxxxxxx/", name = "abstractEntity") public JAXBElement createAbstractEntity(AbstractEntity value) { return new JAXBElement(_AbstractEntity_QNAME, AbstractEntity.class, null, value); }

    }

提交回复
热议问题