Skip to content
Advertisement

Unable to add boolean value to contextProperties map of JAXBDataBinding in cxf beans xml

I am trying to set com.sun.xml.bind.treatEverythingNillable property to true as mentioned in document. But is throwing error.

How can I set the com.sun.xml.bind.treatEverythingNillable to Boolean TRUE Object?

https://cxf.apache.org/docs/jaxb.html

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
        xmlns:cxf="http://cxf.apache.org/core" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd http://www.springframework.org/schema/util 
           http://www.springframework.org/schema/util/spring-util.xsd">
        <!-- <import resource="classpath:META-INF/cxf/cxf.xml" />
        <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
        <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> -->
        <jaxws:endpoint
                xmlns:tns="http://xmlns.chetan.com/oxp/service/v2"
                id="StudentService"
                implementor="com.chetan.webservices.cxf.StudentService"
                wsdlLocation="WEB-INF/wsdl/StudentService.wsdl"
                endpointName="tns:StudentService"
                serviceName="tns:StudentService"
                address="/v2/StudentService">
            <jaxws:dataBinding>
              <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
                <property name="contextProperties">
                  <map>
                    <entry>
                      <key><value>com.sun.xml.bind.treatEverythingNillable</value></key>
                      <value>true</value>
                    </entry>
                  </map>
                </property>
              </bean>
            </jaxws:dataBinding>
        </jaxws:endpoint>
        <bean id="DocumentBuilderFactory" class="com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl">
        </bean>
        <bean id="cxf" class="org.apache.cxf.bus.spring.SpringBus"/>
        <cxf:bus>
            <cxf:properties>
               <entry key="org.apache.cxf.stax.maxChildElements" value="250000"/>
               <entry key="org.apache.cxf.stax.maxElementDepth" value="500"/>
               <!--<entry key="org.apache.cxf.stax.maxAttributeCount" value="500/>-->
               <!-- <entry key="org.apache.cxf.stax.maxAttributeSize" value="65536"/>-->
               <entry key="org.apache.cxf.stax.maxTextLength" value="1073741824"/>
            </cxf:properties>
        </cxf:bus>
</beans> 

Error

Caused by: javax.xml.bind.JAXBException: true is not a valid value for property "com.sun.xml.bind.treatEverythingNillable"
    at com.sun.xml.bind.v2.ContextFactory.getPropertyValue(ContextFactory.java:177)
    at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:99)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:247)
    at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:234)
    at javax.xml.bind.ContextFinder.find(ContextFinder.java:441)
    at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:641)
    at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:345)
    at org.apache.cxf.common.jaxb.JAXBContextCache$2.run(JAXBContextCache.java:343)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.apache.cxf.common.jaxb.JAXBContextCache.createContext(JAXBContextCache.java:343)
    at org.apache.cxf.common.jaxb.JAXBContextCache.getCachedContextAndSchemas(JAXBContextCache.java:245)
    at org.apache.cxf.jaxb.JAXBDataBinding.createJAXBContextAndSchemas(JAXBDataBinding.java:496)
    at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:355)
    ... 44 more

Windows 10 + JDK8 + Tomcat 8.75 + JAXB 3.3.10

Advertisement

Answer

Copy / pasting the answer from the ticket (https://issues.apache.org/jira/browse/CXF-8656). The problem is that you initialize this property with string value “true”, not boolean value true as property expects:

<key><value>com.sun.xml.bind.treatEverythingNillable</value></key>
<value>true</value>

Please use:

 <key><value>com.sun.xml.bind.treatEverythingNillable</value></key>
 <value type="java.lang.Boolean">true</value>
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement