简体   繁体   English

JaxB无法封送,说缺少RootElement但有一个

[英]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. 我已经看到了解决此问题存在职位,但因为我是新来的JAXB我有一个有点麻烦,我有一个根元素设置和藏汉宣布我的XML元素。 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 但这是我的SearchRequest类

@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 如何设置searchControls,条件和过滤器

@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 如何我正在解组为使用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. 这里的问题是,用于创建依赖项jar的Ant构建是旧版本,需要重做ant构建,并修复所有错误。 I was converting Castor to Jaxb, so the set up of elements are correct so can be used as a reference point. 我将Castor转换为Jaxb,因此元素的设置是正确的,因此可以用作参考点。

For people having this issue and it not being a dependancy issue, the most likly cause of the problem is in your marshalling. 对于有此问题但又不是依赖问题的人,最可能导致该问题的原因是您的编组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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