So the below will return the json representation of the Object o? No other
setup is needed? Thanks for the quick responses!
@GET
@Path("/topspamsenderjson")
@Produces("application/json")
public Object getTopSpamSenderData() throws Exception
{
Object o = topSpamSenderService.getTopSpamSender();
return o;
}
KARR, DAVID (ATTCINW) wrote:
>
>> -----Original Message-----
>> From: cgswtsu78 [mailto:[email protected]]
>> Sent: Tuesday, December 01, 2009 3:07 PM
>> To: [email protected]
>> Subject: RE: How to use CXF and JSON
>>
>>
>> Ok, I've made that switch, but I'm still confused as how I need to
>> setup the
>> javax.ws.rs.core.Response. How would I take an Object and convert it
>> into a
>> json string? Below is the xml sample I created, any suggestions on
>> converting this to a json implementation would be greatly appreciated.
>
> I wondered what you were talking about in your previous note.
> Typically, you don't do anything to format the response except for
> returning the object from the method. The container does the work of
> formatting the response in either XML or JSON. Most of this code you've
> written wasn't necessary. You can modify the formatting of the response
> with "@Xml..." annotations (which also can affect the JSON output), but
> mostly you just let the container do the work.
>
>> KARR, DAVID (ATTCINW) wrote:
>> >
>> >> -----Original Message-----
>> >> From: cgswtsu78 [mailto:[email protected]]
>> >> Sent: Tuesday, December 01, 2009 2:44 PM
>> >> To: [email protected]
>> >> Subject: How to use CXF and JSON
>> >>
>> >>
>> >> Hello,
>> >>
>> >> I'm very new to building RESTful webservices using apache cxf and I
>> >> currently have a small sample that returns a
>> javax.ws.rs.core.Response
>> >> in
>> >> xml format using the @ProduceMime("application/xml"). My question
>> is
>> >> how do
>> >> I return a javax.ws.rs.core.Response in JSON format? I've tried
>> using
>> >> @ProduceMime("text/json"), @ProduceMime("application/json"). I'm
>> > using
>> >> JAXB
>> >> to convert the object to xml and then rebuilding the response, but
>> I'm
>> >> not
>> >> sure how to rebuild the response when I return json. Is this
>> possible
>> >> with
>> >> CXF?
>> >
>> > The "old" "@ProduceMime" annotation has been replaced with
>> "@Produces".
>> >
>> > The following will make a method produce either XML or JSON,
>> depending
>> > on the Accept header value:
>> >
>> > @Produces({"application/xml", "application/json"})
>> >
>> >
>>
>> --
>> View this message in context:
> http://old.nabble.com/How-to-use-CXF-and-
>> JSON-tp26600386p26600710.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>
>
>
--
View this message in context:
http://old.nabble.com/How-to-use-CXF-and-JSON-tp26600386p26601037.html
Sent from the cxf-user mailing list archive at Nabble.com.