You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Coder One <co...@yahoo.com> on 2008/06/06 05:35:07 UTC
CXF & JSON Response
I got my CXF JAX-RS service going but the response is cryptic: No message body writer found for response class : AlertMsg.
Browsing the archive, I found the solution, but it looks "roundabout". I don't like the need to annotate my response bean with JAXB stuff. An analogy is that Web Services (SOAP) do not require annotations/registration of writers of the response beans...why CXF/JAX-RS? Thanks...
@GET
@Path("/getAlertMsg/{aId}")
@ProduceMime("application/json")
public AlertMsg getAlertMsg(@PathParam("aId") String aId)
public class AlertMsg implements java.io.Serializable
{
private String a;
private String[] b;
}
Re: CXF & JSON Response
Posted by Coder One <co...@yahoo.com>.
--- On Fri, 6/6/08, Sergey Beryozkin <se...@iona.com> wrote:
>> Current JSON provider on the trunk works with a JAXBContext
> in tandem and it can only acquire a JAXBContext
> if XMLRootElement annotation is available. Once the patch
> I'm slowly working upon is commited, it will be able to
> acquire contexts
Fantastic!
> Trying to provide your own message provider can be a
> reasonable solution. Runtime won't always be able to do
> the (de)serialzation
> the way you expect (dur to a custom nature of a given type
> or due to the fact it's not capable of doing the given
> moment of time)
This worries me a bit. Our "standard" for remote interfaces is to use only primitive java data types (byte, short, long, String, float, double) along with arrays, possibly List and Map, and that's it. A standard message provider ought to handle that right? Trying to think of practices to avoid so we do not have to write custom message writers.
> and in such cases being able to provide your own provider
> is really handly
Yes...but that's a lot of work :) A major benefit with a framework such as CXF is the automated data binding...:)
Thanks again!
> Cheers, Sergey
>
>
> >I got my CXF JAX-RS service going but the response is
> cryptic: No message body writer found for response class :
> AlertMsg.
> >
> > Browsing the archive, I found the solution, but it
> looks "roundabout". I don't like the need to
> annotate my response bean with
> > JAXB stuff. An analogy is that Web Services (SOAP) do
> not require annotations/registration of writers of the
> response beans...why
> > CXF/JAX-RS? Thanks...
> >
> > @GET
> > @Path("/getAlertMsg/{aId}")
> > @ProduceMime("application/json")
> > public AlertMsg
> getAlertMsg(@PathParam("aId") String aId)
> >
> >
> > public class AlertMsg implements java.io.Serializable
> > {
> > private String a;
> > private String[] b;
> > }
> >
> >
> >
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road,
> Dublin 4, Ireland
Re: CXF & JSON Response
Posted by Sergey Beryozkin <se...@iona.com>.
Hi
Current JSON provider on the trunk works with a JAXBContext in tandem and it can only acquire a JAXBContext
if XMLRootElement annotation is available. Once the patch I'm slowly working upon is commited, it will be able to acquire contexts
if an ObjectFactory is available in a package and thus you'd be able to avoid annotating classes like AlertMsg.
If you'd like to avoid dealing with JAXB at all then another alternative is to use Aegis and I'm considering adding a basic Aegis
provider as well.
Trying to provide your own message provider can be a reasonable solution. Runtime won't always be able to do the (de)serialzation
the way you expect (dur to a custom nature of a given type or due to the fact it's not capable of doing the given moment of time)
and in such cases being able to provide your own provider is really handly
Cheers, Sergey
>I got my CXF JAX-RS service going but the response is cryptic: No message body writer found for response class : AlertMsg.
>
> Browsing the archive, I found the solution, but it looks "roundabout". I don't like the need to annotate my response bean with
> JAXB stuff. An analogy is that Web Services (SOAP) do not require annotations/registration of writers of the response beans...why
> CXF/JAX-RS? Thanks...
>
> @GET
> @Path("/getAlertMsg/{aId}")
> @ProduceMime("application/json")
> public AlertMsg getAlertMsg(@PathParam("aId") String aId)
>
>
> public class AlertMsg implements java.io.Serializable
> {
> private String a;
> private String[] b;
> }
>
>
>
----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland