Not sure if this is going to be the right place to post about this, so
please forgive me. I don't know who owns the Jettison project....
I am using CXF. My problem is this. The object as follows throws an
exception ( listed at the end of this email) when I try to access it
through JSON. The XML access works fine and I get the correct XML. Note
that the annotations have no effect on the issue. The problem seems to
stem from the fact that the code is trying to turn a JSONArray into a
JSONObject. But I cant determine why that might be the case.
Any help would be greatly appreciated.
Thanks,
~Derek Shaw
The object rest method is:
@Get
@HttpResource(location = "/player/{ID}")
@WebResult(name = "Player")
public Player getPlayer(@WebParam(name = "ID") int ID)
throws PlayerNotFoundFault, PlayerFault;
The Player object is: (note that if I remove the List<T> objects the
problem goes away. )
package com.fm.shinyfun.player;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import com.fm.shinyfun.comment.Comment;
import com.fm.shinyfun.media.Media;
@XmlRootElement(name = "player", namespace = "##default")
public class Player implements IPlayer {
private String description = "";
private int id = 0;
private String title = "";
private int userID = 0;
private int commentCount;
private int mediaCount;
private List<Comment> commentList = null;
private List<Media> mediaList = null;
@XmlElement(name = "description")
public String getDescription() {
return description;
}
@XmlAttribute(name = "ID")
public int getID() {
return id;
}
@XmlElement(name = "title")
public String getTitle() {
return title;
}
@XmlElement(name = "userID")
public int getUserID() {
return userID;
}
public void setDescription(String description) {
this.description = description;
}
public void setTitle(String title) {
this.title = title;
}
public void setID(int id) {
this.id = id;
}
public void setUserID(int userID) {
this.userID = userID;
}
@XmlElement(name = "commentCount")
public int getCommentCount() {
return commentCount;
}
public void setCommentCount(int totalNumComments) {
this.commentCount = totalNumComments;
}
@XmlElement(name = "mediaCount")
public int getMediaCount() {
return mediaCount;
}
public void setMediaCount(int totalNumMedia) {
this.mediaCount = totalNumMedia;
}
@XmlElementWrapper(name = "commentList")
@XmlElement(name = "comment")
public List<Comment> getCommentList() {
return commentList;
}
public void setCommentList(List<Comment> comments) {
this.commentList = comments;
}
public void addComment(Comment comment) {
if(this.commentList == null)
this.commentList = new
ArrayList<Comment>();
this.commentList.add(comment);
}
@XmlElementWrapper(name = "mediaList")
@XmlElement(name = "media")
public List<Media> getMediaList() {
return mediaList;
}
public void setMediaList(List<Media> media) {
this.mediaList = media;
}
public void addMedia(Media media) {
if(this.mediaList == null)
this.mediaList = new
ArrayList<Media>();
this.mediaList.add(media);
}
}
Exception:
INFO: URIParameterInterceptor handle message on path [/player/3733721]
with content-type [null]
App:Derek-ShawWP,Level:debug,Notes:thread count increased to
47,Time:2007-07-20 15:37:57.606,Thread:fmDThread-11:ThreadCountMonitor,
Jul 20, 2007 8:38:50 AM org.apache.cxf.phase.PhaseInterceptorChain
doIntercept
INFO: Interceptor has thrown exception, unwinding now
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(BareOutInter
ceptor.java:67)
at
org.apache.cxf.binding.xml.interceptor.XMLMessageOutInterceptor.handleMe
ssage(XMLMessageOutInterceptor.java:71)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:206)
at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outgoi
ngChainInterceptor.java:73)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:206)
at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati
onObserver.java:67)
at
org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDes
tination.java:100)
at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(Ser
vletController.java:224)
at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletControl
ler.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(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:210)
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
51)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:87
0)
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: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(Mapped
XMLStreamWriter.java:93)
at
org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(Mapped
XMLStreamWriter.java:130)
at
org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(Mapped
XMLStreamWriter.java:134)
at
com.sun.xml.bind.v2.runtime.output.XMLStreamWriterOutput.attribute(XMLSt
reamWriterOutput.java:88)
at
com.sun.xml.bind.v2.runtime.output.XmlOutputAbstractImpl.attribute(XmlOu
tputAbstractImpl.java:70)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.attribute(XMLSerializer.java:4
13)
at
com.sun.xml.bind.v2.runtime.property.AttributeProperty.serializeAttribut
es(AttributeProperty.java:63)
at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeAttributes(ClassB
eanInfoImpl.java:295)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.j
ava:617)
at
com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeI
tem(ArrayElementNodeProperty.java:29)
at
com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListB
ody(ArrayElementProperty.java:132)
at
com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(Array
ERProperty.java:101)
at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInf
oImpl.java:286)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializ
er.java:532)
at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInf
oImpl.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:1
48)
at
org.apache.cxf.jaxb.JAXBEncoderDecoder.marshall(JAXBEncoderDecoder.java:
138)