Well it turned out that I had too many jaxb jars in my classpath so now
the xmlseealso works, but I get this odd exception as an invalid
namespace - I'm not quite sure why I'm getting it though, do I need to
specify another namespace somewhere? At this point, I'm not specifying
it anywhere - my bean.xml looks like...
(for this service>
<jaxrs:server id="boardservice" address="/">
<jaxrs:serviceBeans>
<bean class="com.cbs.bos.ws.BoardService" />
</jaxrs:serviceBeans>
</jaxrs:server>
And the exception
INFO: Interceptor has thrown exception, unwinding now
java.lang.IllegalStateException: Invalid JSON namespace:
http://www.w3.org/2001/XMLSchema-instance
at
org.codehaus.jettison.mapped.MappedNamespaceConvention.getJSONNamespace(
MappedNamespaceConvention.java:148)
at
org.codehaus.jettison.mapped.MappedNamespaceConvention.createAttributeKe
y(MappedNamespaceConvention.java:136)
at
org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(Mapped
XMLStreamWriter.java:89)
at
com.sun.xml.bind.v2.runtime.output.XMLStreamWriterOutput.attribute(XMLSt
reamWriterOutput.java:133)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.attribute(XMLSerializer.java:4
31)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.j
ava:676)
at
com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeI
tem(ArrayElementNodeProperty.java:65)
at
com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListB
ody(ArrayElementProperty.java:168)
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:90)
at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRS
OutInterceptor.
-----Original Message-----
From: Daniel Kulp [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 23, 2008 10:28 AM
To: [email protected]
Cc: Vespa, Anthony J
Subject: Re: JSON and JAX-RS
On Tuesday 22 January 2008, Vespa, Anthony J wrote:
> Interesting. Would that mean I would have to use seekAlso and list
> all of the objects that could possibly be returned - I have currently
> about six types of custom objects. What if I was returning a type
> like a boolean or just a string?
You should be fine. (although, you probably need to wrapper them with a
JAXBElement to get the element name) I think all the stuff that maps
to straight xsd schema types are always part of the created JAXBContext.
The stuff you need to be careful of are the things that would be
generated from the xjc.
Dan
>
> ________________________________
>
> From: Daniel Kulp [mailto:[EMAIL PROTECTED]
> Sent: Tue 1/22/2008 5:31 PM
> To: [email protected]
> Cc: Vespa, Anthony J
> Subject: Re: JSON and JAX-RS
>
>
>
>
> Well, looking at the code, it seems to create a new JAXBContext for
> each top level type, which really sucks. IMO, it should use our
> JAXBDatabinding in some way which would allow it/you to configure
> things via spring or something so one one JAXBContext is created/used
> that would have all the required types in it. Actually, checking if
> there is an ObjectFactory in the package and creating the context
> based on that would also go a long way to helping.
>
> That said, with JAXB 2.1, you can probably add an @XmlSeeAlso
> annation on the wsResponse that points to the wsMessage to make the
> JAXBContext for the wsResponse be able to marshal the wsMessage as
> well.
>
> Dan
>
> On Tuesday 22 January 2008, Vespa, Anthony J wrote:
> > So I spent some time playing with JAX-RS and I seem to have
> > encountered an issue.
> >
> > I can return single objects from my service as JSON (standard Java
> > types as well as my custom objects) but if I try to return my
> > wrapper object which contains an anytype generic list, I get an
> > exception.
> >
> > Effectively I have an object called wsResponse that, in this case,
> > is returning an array of messages (wsMessage) - I have decorated
> > both objects with the XMLType. I am looking into this exception and
> > see references to JAXB; is it possible to get around this?
> >
> >
> >
> > Jan 22, 2008 4:45:26 PM
> > org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
> > INFO: Available content types for response is: application/json,
> > Jan 22, 2008 4:45:26 PM
> > org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
> > INFO: Response EntityProvider is:
> > org.apache.cxf.jaxrs.provider.JSONProvider
> > Jan 22, 2008 4:45:26 PM
> > org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
> > INFO: Response content type is: application/json
> > javax.xml.bind.MarshalException
> > - with linked exception:
> > [javax.xml.bind.JAXBException: class com.cbs.bos.data.ws.wsMessage
> > nor any of its super class is known to this context.]
> > at
> > com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java
> >:2 95 )
> > at
> > com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.ja
> >va
> >
> >:1 48)
> >
> > at
> > org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java
> >:9 0) at
> > org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(J
> >AX RS OutInterceptor.java:99)
> > at
> > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercep
> >to rC hain.java:208)
> > at
> > org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Ou
> >tg oi ngChainInterceptor.java:74)
> > at
> > org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercep
> >to rC hain.java:208)
> > at
> > org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInit
> >ia ti onObserver.java:78)
> > at
> > org.apache.cxf.transport.servlet.ServletDestination.doMessage(Servle
> >tD es tination.java:79)
> > at
> > org.apache.cxf.transport.servlet.ServletController.invokeDestination
> >(S er vletController.java:264)
> > at
> > org.apache.cxf.transport.servlet.ServletController.invoke(ServletCon
> >tr ol ler.java:123)
> > at
> > org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractC
> >XF Se rvlet.java:170)
> > at
> > org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCX
> >FS er 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(App
> >li ca tionFilterChain.java:290)
> > at
> > org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
> >Fi lt erChain.java:206)
> > at
> > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapper
> >Va lv e.java:233)
> > at
> > org.apache.catalina.core.StandardContextValve.invoke(StandardContext
> >Va lv e.java:175)
> > at
> > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.
> >ja va
> >
> > :128)
> >
> > at
> > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.
> >ja va
> >
> > :102)
> >
> > at
> > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVa
> >lv e. java:109)
> > at
> > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.ja
> >va
> >
> >:2 63)
> >
> > at
> > org.apache.coyote.http11.Http11Processor.process(Http11Processor.jav
> >a: 84 4)
> > at
> > org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proc
> >es s( Http11Protocol.java:584)
> > at
> > org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:4
> >47 )
>
> --
> J. Daniel Kulp
> Principal Engineer, IONA
> [EMAIL PROTECTED]
> http://www.dankulp.com/blog
--
J. Daniel Kulp
Principal Engineer, IONA
[EMAIL PROTECTED]
http://www.dankulp.com/blog