Hi This should be fixed in http://jira.codehaus.org/browse/JETTISON-38, Jettison 1.1-SNAPSHOT ...
can you please download that version, replace the one shipped by CXF and see what happens ? Cheers, Sergey ----- Original Message ----- From: <[EMAIL PROTECTED]> To: <[email protected]> Sent: Tuesday, April 29, 2008 3:12 PM Subject: [JAX-RS] REST/JSON Issue : EmptyStackException Hi, Here is a problem wich make me crazy an half day :o/ having an jettison "EmptyStackException" when asking "application/bson" but no problem when trying to get "text/xml" ... My application got a lots of complex objects so i reproduce here the problem in a small sample to understand it... Got a simple HTTP GET method "getScores()" wich return a "Scores" ..wich is an array of "Score". And a "Score" is a "Person" P, and a "Long" score. @GET @Path("/getScores/") public Scores getScores() { Scores s = new Scores(); Score s1 = new Score(); s1.setP(new Person("Joe")); s1.setScore(new Long(10)); ArrayList<Score> scoresResult = new ArrayList<Score>(); scoresResult.add(s1); s.setScore(scoresResult); return s; } the "Scores" class : @XmlRootElement(name = "Scores") public class Scores { private Collection<Score> scores; public Scores() { scores = new ArrayList<Score>(); } public Collection<Score> getScore() { return scores; } public void setScore(Collection<Score> s) { this.scores = s; } } the "Score" class : @XmlRootElement(name = "Score") public class Score implements Serializable{ private Person p; private Long score; (...constructor/getter/setters...) } You should see that there is an attribute named "score" as the class name..(so the way to get EmptyStackException) When i try to access "getScores" in REST/XML : C:\>telnet myhost 8080 GET /api/rest/HW/getScores/ HTTP/1.0 Accept: text/xml there is no problem, i got the result : HTTP/1.1 200 OK Server: Apache-Coyote/1.1 Content-Type: text/xml Content-Length: 72 Date: Tue, 29 Apr 2008 13:44:23 GMT Connection: close <Scores><score><p><name>Joe</name></p><score>10</score></score></Scores> But when i try to access getScores" in REST/json : C:\>telnet myhost 8080 GET /api/rest/HW/getScores/ HTTP/1.0 Accept: application/json An exception occur... Here is the client result : HTTP/1.1 500 Erreur Interne de Servlet Server: Apache-Coyote/1.1 Content-Type: application/json;charset=UTF-8 Content-Length: 195 Date: Tue, 29 Apr 2008 13:46:49 GMT Connection: close <ns1:XMLFault xmlns:ns1="http://cxf.apache.org/bindings/xformat"><ns1:faultstring xmlns:ns1="http://cxf.apache.org/bindings/xformat">java.util.EmptyStackE xception</ns1:faultstring></ns1:XMLFault> Here is the server stack trace : 14:46 INFO [interceptor.JAXRSInInterceptor] - Found operation: getScores 14:46 INFO [phase.PhaseInterceptorChain] - Interceptor has thrown exception, unwinding now java.util.EmptyStackException at org.codehaus.jettison.util.FastStack.peek(FastStack.java:39) at org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeEndElement(Mappe dXMLStreamWriter.java:206) at com.sun.xml.bind.v2.runtime.output.XMLStreamWriterOutput.endTag(XMLStrea mWriterOutput.java:144) at com.sun.xml.bind.v2.runtime.output.XmlOutputAbstractImpl.endTag(XmlOutpu tAbstractImpl.java:120) at com.sun.xml.bind.v2.runtime.output.NamespaceContextImpl$Element.endEleme nt(NamespaceContextImpl.java:491) at com.sun.xml.bind.v2.runtime.XMLSerializer.endElement(XMLSerializer.java: 310) at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListB ody(ArrayElementProperty.java:171) at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(Array ERProperty.java:152) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInf oImpl.java:322) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializ er.java:589) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInf oImpl.java:312) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java :490) at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328 ) at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:1 75) at org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:102 ) at org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRS OutInterceptor.java:110) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC hain.java:220) at org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outgoi ngChainInterceptor.java:74) at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC hain.java:220) at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati onObserver.java:78) at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestin ation.java:92) at org.apache.cxf.transport.servlet.ServletController.invokeDestination(Ser vletController.java:214) at org.apache.cxf.transport.servlet.ServletController.invoke(ServletControl ler.java:113) at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFSe rvlet.java:170) at org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFSer vlet.java:152) 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(Applica tionFilterChain.java:269) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:188) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:213) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.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:1 74) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:87 4) at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.proc essConnection(Http11BaseProtocol.java:665) at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint .java:528) at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollow erWorkerThread.java:81) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool .java:689) at java.lang.Thread.run(Thread.java:810) The issue is here to rename the "score" attribute of the "Score" class. This problem seems to be easy to solve, but when you got a complex return type (ie. with an attribute called like a super-super-class name) it's not so easy to find why this exception occur.. Anyway, i got 2 questions : 1) why is it not possible to name an attribute as a ancester class name ? Is it a jettison bug ? (if so, if anyone could follow it to the jettison team..) 2) why, when accepting "application/json" content, i got a XML Fault content (Content-Type: application/json but it's here text/xml fault result !) Version used : - CXF 2.1 SNAPSHOT 11/04 : apache-cxf-2.1-incubator-20080411.173632-48 - I just replace JETTISON by the last snapshot 24/04 : jettison-1.1-20080424.080632-3.jar PS: sorry for my english which is not always simple to understand ;) Regards Brice Vandeputte ---------------------------- IONA Technologies PLC (registered in Ireland) Registered Number: 171387 Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
