简体   繁体   中英

JaxB unable to marshall, says missing RootElement but has one

I have seen posts that exist around this issue, but as I am new to jaxB I am having a bit of trouble I have a Root element set up and declaring my XML elements aswell. what am I doing wrong here?

I am getting this error

org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "au.test.Search.ws.model.SearchRequest" as an element because it is missing an @XmlRootElement annotation]

However this is my SearchRequest Class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
        "searchControls",
        "searchCriteria",
        "searchFilters"
})
@XmlRootElement(name = "searchRequest")
public class SearchRequest {

    @XmlElement(required = true)
    protected SearchControls searchControls;
    @XmlElement(required = true)
    protected NameSearchCriteria searchCriteria;
    @XmlElement
    protected NameSearchFilters searchFilters;

    public SearchControls getSearchControls() {
        return searchControls;
    }

    public void setSearchControls(SearchControls value) {
        this.searchControls = value;
    }

    public NameSearchCriteria getSearchCriteria() {
        return searchCriteria;
    }

    public void setSearchCriteria(NameSearchCriteria value) {
        this.searchCriteria = value;
    }

    public NameSearchFilters getSearchFilters() {
        return searchFilters;
    }

    public void setSearchFilters(NameSearchFilters value) {
        this.searchFilters = value;
    }
}

How searchControls,criteria and Filters are set up

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "NameSearchFilters", propOrder = {

})
public class NameSearchFilters {

    protected FilterOperator operator;

    public FilterOperator getOperator() {
        return operator;
    }

    public void setOperator(FilterOperator value) {
        this.operator = value;
    }
}

How i am unmarshalling as requested using org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive

public SearchResponse performSearch(SearchRequest searchRequest) {
    searchResponse = (SearchResponse) getWebServiceTemplate()
            .marshalSendAndReceive(searchRequest);            

The issue here was that the Ant builds creating dependancy jar was an old version, the ant build needed to be redone and all errors fixed. I was converting Castor to Jaxb, so the set up of elements are correct so can be used as a reference point.

For people having this issue and it not being a dependancy issue, the most likly cause of the problem is in your marshalling.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM