2

在我的 Response.xsd 我有很多元素,如:

...
<xs:element type="xs:string" name="carModel" minOccurs="0">
</xs:element>
...

JAXBClasses.xsd. 结果:

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        //...
        "carModel"
        //...
    })
    public static class Car{

    //...
    protected String carModel;
    //...getter and setters.

    }

构建我的 WebService 响应:

  Car car = new Car();
  //other params
  car.setCarModel(null); 

在生成的响应中,我得到:

 <ax23:carModel xsi:nil="true"/>

但我预计完全没有carModel标签。我想完全跳过

我做错了什么?默认情况下,为什么null会变成nil何时nillable = false

我不确定,这就是你要求@Xstian 的:

我的一部分web.xml

<servlet>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>
        org.apache.axis2.transport.http.AxisServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
</servlet-mapping>

我的WEB-INF/services/CarService/META-INF/services.xml

<service name="CarService" >
<Description>
    Please Type your service description here
</Description>
<messageReceivers>
    <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
    <messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out"  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
</messageReceivers>
<parameter name="ServiceClass" locked="false">com.foo.ws.CarService</parameter>
</service>
4

1 回答 1

1

使用此注释@XmlElement(nillable=false)

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    //...
    "carModel"
    //...
})
public static class Car{

//...
@XmlElement(nillable=false)
protected String carModel;
//...getter and setters.

}
于 2015-07-16T07:56:45.060 回答