为什么CXF返回一个空数组而不是null?

时间:2014-12-31 15:37:56

标签: web-services cxf

这与我关于CXF proxies not accepting nulls的其他问题有关。

从这个自动生成的WSDL:

<xs:complexType name="someMethod2">
    <xs:sequence>
        <xs:element maxOccurs="unbounded" minOccurs="0" nillable="true" name="params2" type="xs:string"/>
    </xs:sequence>
</xs:complexType>

生成这样的代理:

public class SomeMethod2
{
    protected String[] params2; 
    ...
    public String[] getParams2()
    {
        // CXF replaces null with an empty array
        if (this.params2== null)
        {
            return new String[0];
        }
        String[] retVal = new String[this.params2.length];
        System.arraycopy(this.params2, 0, retVal, 0, this.params2.length);
        return (retVal);
    }
    ...
}

正如您所看到的,在“getOtherParams”中,null被切换为空String数组。这会导致遗留代码中的问题依赖于接收硬空值。为什么CXF会这样做,有没有办法配置CXF / JAXB / JAXWS来强制返回实际的空值?

0 个答案:

没有答案
相关问题