[
https://issues.apache.org/jira/browse/CXF-852?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12523735
]
Sriram Chavali commented on CXF-852:
------------------------------------
I have also ran into this issue. It happens when the # of nodes to be
marshalled is > 1. If it is 1, then there is no problem. Issue seems to be in
org.codehaus.jettison.mapped.MappedXMLStreamWriter
Is there a separate tracker for the Jettison project?
> Array responses containing XmlAttribute cause exception in jettison
> -------------------------------------------------------------------
>
> Key: CXF-852
> URL: https://issues.apache.org/jira/browse/CXF-852
> Project: CXF
> Issue Type: Bug
> Components: Core
> Affects Versions: 2.0
> Environment: Windows XP, Java 1.5
> Reporter: Derek Shaw
>
> When outputing lists of elements to JSON with an interface such as:
> @Get
> @HttpResource(location =
> "/media/objects/{containerID}/{startIndex}/{endIndex}")
> public List<Media> getMediaObjectList( @WebParam(name = "containerID")
> int containerID,
>
> @WebParam(name = "startIndex") int startIndex,
>
> @WebParam(name = "endIndex") int endIndex)
>
> throws MediaFault;
> If the object within the array contains an XmlAttribute annotation on one of
> its properties an exception is thrown in Jettison when retrieving the json
> response. Note that the XML response works as expected. The problem seems to
> be located at writeAttribute() in MappedXMLStreamWriter. The code attempts to
> cast a JSONArray to a JSONObject. Looks like perhaps there needs to be an
> instance of check as there is in other locations. Or that it is prematurely
> attempting to output the attribute before pulling the underlying object out
> of the Array, though this is just a guess....
> The workaround for me is to change the @XmlAttribute on the contained object
> to an @XmlElement.
> Here is the exception:
> org.apache.cxf.interceptor.Fault: Marshalling Error:
> org.codehaus.jettison.json.JSONArray
> at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:155)
> at org.apache.cxf.jaxb.io.DataWriterImpl.write(DataWriterImpl.java:40)
> at
> org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:98)
> at
> org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:67)
> at
> org.apache.cxf.binding.xml.interceptor.XMLMessageOutInterceptor.handleMessage(XMLMessageOutInterceptor.java:71)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:206)
> at
> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:73)
> at
> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:206)
> at
> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:67)
> at
> org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDestination.java:100)
> at
> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:224)
> at
> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:103)
> at
> org.apache.cxf.transport.servlet.CXFServlet.invoke(CXFServlet.java:261)
> at
> org.apache.cxf.transport.servlet.CXFServlet.doGet(CXFServlet.java:243)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
> at
> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
> at
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
> at
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
> at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
> at java.lang.Thread.run(Thread.java:595)
> Caused by: java.lang.ClassCastException: org.codehaus.jettison.json.JSONArray
> at
> org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(MappedXMLStreamWriter.java:93)
> at
> org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(MappedXMLStreamWriter.java:130)
> at
> org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(MappedXMLStreamWriter.java:134)
> at
> com.sun.xml.bind.v2.runtime.output.XMLStreamWriterOutput.attribute(XMLStreamWriterOutput.java:88)
> at
> com.sun.xml.bind.v2.runtime.output.XmlOutputAbstractImpl.attribute(XmlOutputAbstractImpl.java:70)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.attribute(XMLSerializer.java:413)
> at
> com.sun.xml.bind.v2.runtime.property.AttributeProperty.serializeAttributes(AttributeProperty.java:63)
> at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeAttributes(ClassBeanInfoImpl.java:295)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:617)
> at
> com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:29)
> at
> com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:132)
> at
> com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:101)
> at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:532)
> at
> com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:276)
> at
> com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:461)
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:292)
> at
> com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:148)
> at
> org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:138)
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.