You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Edward Mostrom <em...@gmail.com> on 2011/08/20 06:29:04 UTC

Help using cxfbean to return class as json

Can't figure out how to return a custom class as a json string.  Here is
what I was trying but when I hit:
http://localhost:8080/example/person/4
I get:

No message body writer has been found for response class Person.



#!/usr/bin/env groovy

@Grab(group="org.apache.camel", module="camel-core", version="2.8.0")
@Grab(group="org.apache.camel", module="camel-jetty", version="2.8.0")
@Grab(group="org.apache.camel", module="camel-cxf", version="2.8.0")
@Grab(group='ch.qos.logback', module='logback-classic', version='0.9.29')
import org.apache.camel.CamelContext
import org.apache.camel.impl.DefaultCamelContext
import org.apache.camel.impl.SimpleRegistry
import org.apache.camel.builder.RouteBuilder
import javax.ws.rs.*


class Person {
  Integer id
  String name
}

@Path("/example")
class MyExampleResource{

  @GET
  @Produces("application/json")
  @Path("person/{id}")
  public Person getPerson(@PathParam("id") Integer id){
    Person p = new Person()
    p.id = id
    p.name = "Bob"
    return p
  }
}


CamelContext cxt = new DefaultCamelContext()
cxt.registry = new SimpleRegistry()
cxt.registry.registry.put("myResources", [new MyExampleResource()])
cxt.registry.registry.put("jsonProvider", new
org.apache.cxf.jaxrs.provider.JSONProvider())

cxt.addRoutes(new RouteBuilder(){
  void configure(){
    from("jetty:http://localhost:8080?matchOnUriPrefix=true")
    .to("cxfbean:myResources?providers=#jsonProvider")
  }
})

cxt.start()

Re: Help using cxfbean to return class as json

Posted by Willem Jiang <wi...@gmail.com>.
Hi Edward,

You can consider to send this issue to cxf users mailing list.

On 8/21/11 10:44 AM, Edward wrote:
>
> Figured it out... Just needed to annotate the class... the provide has
> issues with Groovy classes but that is a separate problem.
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Help-using-cxfbean-to-return-class-as-json-tp4717688p4719639.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: Help using cxfbean to return class as json

Posted by Edward <em...@gmail.com>.
Figured it out... Just needed to annotate the class... the provide has
issues with Groovy classes but that is a separate problem.


--
View this message in context: http://camel.465427.n5.nabble.com/Help-using-cxfbean-to-return-class-as-json-tp4717688p4719639.html
Sent from the Camel - Users mailing list archive at Nabble.com.