You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Red Eagle <x....@gmail.com> on 2008/09/26 10:02:54 UTC

Marshalling Error: unable to marshal type "java.lang.String" as an element

Hi,

I get an exception during the marshalling from JAXB classes (Stacktrace 
is at the end of the mail):
"org.apache.cxf.interceptor.Fault: Marshalling Error: unable to marshal 
type "java.lang.String" as an element because it is missing an 
@XmlRootElement annotation"

The JAXB classes are generated with the wsdl2java tool and i added the 
@XmlRootElement tag to the first element by hand. The result is the same 
exception.

I found this closed issue on the JIRA: 
https://issues.apache.org/jira/browse/CXF-497?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12484791 
and search after xs:any tags in my wsdl schema and found this entry:
      
    ...
      <xs:element name="XMLDocument" minOccurs="0">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="XMLContent">
              <xs:complexType>
                <xs:sequence>
                  <xs:any namespace="##any" processContents="lax"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
                    ....
          </xs:sequence>
        </xs:complexType>
      </xs:element>


Indeed i was setting an String to this element. So I tried to replace 
that String with an JAXB Element and the marshalling process works. But 
the result was not satisfying.
Has anyone an idea how to set an String in an any tag?
(Tested cxf version: 2.0.6; 2.0.8)

regards,
Stefan


26.09.2008 09:29:30 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Marshalling Error: unable to marshal 
type "java.lang.String" as an element because it is missing an 
@XmlRootElement annotation
    at 
org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:207)
    at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:63)
    at 
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleHeaderPart(SoapOutInterceptor.java:197)
    at 
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:125)
    at 
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:76)
    at 
org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:57)
    at 
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
    at 
org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:170)
    at $Proxy72.app2Mzs(Unknown Source)
    at at.enno.egov.moa.zs.client.CxfClient.send(CxfClient.java:278)
    at 
at.enno.egov.moa.zs.client.CxfClient$$FastClassByCGLIB$$4dae1743.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at 
org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
    at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at 
org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)
    at 
org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)
    at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at 
org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
    at 
at.enno.egov.moa.zs.client.CxfClient$$EnhancerByCGLIB$$7e14a0cc.send(<generated>)
    at 
at.enno.egov.moa.zs.client.CxfClientIntegrationTest.testSend(CxfClientIntegrationTest.java:76)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at 
org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:163)
    at 
org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
    at 
org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
    at 
org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
    at 
org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
    at 
org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
    at 
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142)
    at 
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
    at 
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    at 
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    at 
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    at 
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
    at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.SAXException2: unable to marshal type "java.lang.String" 
as an element because it is missing an @XmlRootElement annotation]
    at 
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:295)
    at 
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:148)
    at 
org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:358)
    at 
org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:187)
    ... 44 more
Caused by: com.sun.istack.SAXException2: unable to marshal type 
"java.lang.String" as an element because it is missing an 
@XmlRootElement annotation
    at 
com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:225)
    at 
com.sun.xml.bind.v2.runtime.LeafBeanInfoImpl.serializeRoot(LeafBeanInfoImpl.java:101)
    at 
com.sun.xml.bind.v2.runtime.property.SingleReferenceNodeProperty.serializeBody(SingleReferenceNodeProperty.java:74)
    at 
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
    at 
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:619)
    at 
com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:113)
    at 
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
    at 
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:619)
    at 
com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:113)
    at 
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
    at 
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:619)
    at 
com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBody(SingleElementNodeProperty.java:113)
    at 
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:98)
    at 
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBeanInfoImpl.java:127)
    at 
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanInfoImpl.java:244)
    at 
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:251)
    at 
com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanInfoImpl.java:33)
    at 
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:461)
    at 
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:292)
    ... 47 more



Re: Marshalling Error: unable to marshal type "java.lang.String" as an element

Posted by Daniel Kulp <dk...@apache.org>.
> Has anyone an idea how to set an String in an any tag?

You cannot.   <xs:any> needs to have element content and needs an element 
name.   A string wouldn't have one.   

The generated ObjectFactory would have methods to create the appropriate 
JAXBElement for the String if you don't want to code in the QName.

Alternatively, change the schema to something like:
 <xs:element name="content" type="xs:anyType"/>
so the element name is specified, but it can hold any "type".


Dan




On Friday 26 September 2008 4:02:54 am Red Eagle wrote:
> Hi,
>
> I get an exception during the marshalling from JAXB classes (Stacktrace
> is at the end of the mail):
> "org.apache.cxf.interceptor.Fault: Marshalling Error: unable to marshal
> type "java.lang.String" as an element because it is missing an
> @XmlRootElement annotation"
>
> The JAXB classes are generated with the wsdl2java tool and i added the
> @XmlRootElement tag to the first element by hand. The result is the same
> exception.
>
> I found this closed issue on the JIRA:
> https://issues.apache.org/jira/browse/CXF-497?page=com.atlassian.jira.plugi
>n.system.issuetabpanels:comment-tabpanel#action_12484791 and search after
> xs:any tags in my wsdl schema and found this entry:
>
>     ...
>       <xs:element name="XMLDocument" minOccurs="0">
>         <xs:complexType>
>           <xs:sequence>
>             <xs:element name="XMLContent">
>               <xs:complexType>
>                 <xs:sequence>
>                   <xs:any namespace="##any" processContents="lax"/>
>                 </xs:sequence>
>               </xs:complexType>
>             </xs:element>
>                     ....
>           </xs:sequence>
>         </xs:complexType>
>       </xs:element>
>
>
> Indeed i was setting an String to this element. So I tried to replace
> that String with an JAXB Element and the marshalling process works. But
> the result was not satisfying.
> Has anyone an idea how to set an String in an any tag?
> (Tested cxf version: 2.0.6; 2.0.8)
>
> regards,
> Stefan
>
>
> 26.09.2008 09:29:30 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
> INFO: Interceptor has thrown exception, unwinding now
> org.apache.cxf.interceptor.Fault: Marshalling Error: unable to marshal
> type "java.lang.String" as an element because it is missing an
> @XmlRootElement annotation
>     at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:207
>) at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:63) at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleHeaderPart
>(SoapOutInterceptor.java:197) at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelop
>eStart(SoapOutInterceptor.java:125) at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(So
>apOutInterceptor.java:76) at
> org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(So
>apOutInterceptor.java:57) at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChai
>n.java:221) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:276) at
> org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222) at
> org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73) at
> org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:170)
>     at $Proxy72.app2Mzs(Unknown Source)
>     at at.enno.egov.moa.zs.client.CxfClient.send(CxfClient.java:278)
>     at
> at.enno.egov.moa.zs.client.CxfClient$$FastClassByCGLIB$$4dae1743.invoke(<ge
>nerated>) at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) at
> org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invo
>keJoinpoint(Cglib2AopProxy.java:700) at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflec
>tiveMethodInvocation.java:149) at
> org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed
>(DelegatingIntroductionInterceptor.java:131) at
> org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(De
>legatingIntroductionInterceptor.java:119) at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Reflec
>tiveMethodInvocation.java:171) at
> org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.
>intercept(Cglib2AopProxy.java:635) at
> at.enno.egov.moa.zs.client.CxfClient$$EnhancerByCGLIB$$7e14a0cc.send(<gener
>ated>) at
> at.enno.egov.moa.zs.client.CxfClientIntegrationTest.testSend(CxfClientInteg
>rationTest.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method) at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
>9) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
>l.java:25) at java.lang.reflect.Method.invoke(Method.java:597)
>     at
> org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestM
>ethod.java:163) at
> org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(Sp
>ringMethodRoadie.java:233) at
> org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTe
>stThenAfters.run(SpringMethodRoadie.java:333) at
> org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitio
>ns(SpringMethodRoadie.java:217) at
> org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMe
>thodRoadie.java:197) at
> org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethod
>Roadie.java:143) at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestM
>ethod(SpringJUnit4ClassRunner.java:142) at
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.j
>ava:51) at
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:4
>4) at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
>     at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
>     at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
>     at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestRe
>ference.java:38) at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
>38) at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR
>unner.java:460) at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR
>unner.java:673) at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner
>.java:386) at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunne
>r.java:196) Caused by: javax.xml.bind.MarshalException
>  - with linked exception:
> [com.sun.istack.SAXException2: unable to marshal type "java.lang.String"
> as an element because it is missing an @XmlRootElement annotation]
>     at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:295)
>     at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:148)
>     at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.writeObject(JAXBEncoderDecoder.java:
>358) at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:187
>) ... 44 more
> Caused by: com.sun.istack.SAXException2: unable to marshal type
> "java.lang.String" as an element because it is missing an
> @XmlRootElement annotation
>     at
> com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:22
>5) at
> com.sun.xml.bind.v2.runtime.LeafBeanInfoImpl.serializeRoot(LeafBeanInfoImpl
>.java:101) at
> com.sun.xml.bind.v2.runtime.property.SingleReferenceNodeProperty.serializeB
>ody(SingleReferenceNodeProperty.java:74) at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoIm
>pl.java:286) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java
>:619) at
> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBod
>y(SingleElementNodeProperty.java:113) at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoIm
>pl.java:286) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java
>:619) at
> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBod
>y(SingleElementNodeProperty.java:113) at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoIm
>pl.java:286) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java
>:619) at
> com.sun.xml.bind.v2.runtime.property.SingleElementNodeProperty.serializeBod
>y(SingleElementNodeProperty.java:113) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBean
>InfoImpl.java:98) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl$1.serializeBody(ElementBean
>InfoImpl.java:127) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeBody(ElementBeanIn
>foImpl.java:244) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanIn
>foImpl.java:251) at
> com.sun.xml.bind.v2.runtime.ElementBeanInfoImpl.serializeRoot(ElementBeanIn
>foImpl.java:33) at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:46
>1) at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:292)
>     ... 47 more



-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog