Seems like this is not a very new thread. I hope you got this figured out. In
case you didn't or in case somebody else come here... here is the answer:
You annotate it as @Produces({"application/xml","application/json"}) - see
the value is an array. When the client needs JSON output it need to set
header parameter "Accept" as "application/json" and call the service. The
service will return data as JSON. I have also come across Restclient 2.3
(Available in code.google.com - search in google for Restclient). It is a
wonderful client to test RESTful webservices.
Hope this helps.
Hari Gangadharan
hanasakijiji wrote:
>
> The annotation does not seem to like that. Also, how would the caller
> / invoker specify if they want JSON or XML back?
>
> [ERROR]Mojo:
> [ERROR] org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile
> [ERROR]FAILED for project:
> [ERROR] com.hanaden:DemoRestful-WAR:war:1.0-SNAPSHOT
> [ERROR]Reason:
> [ERROR]com/service/impl/ServiceImpl.java.java:[23,10] annotation
> values must be of the form 'name=value'
> [ERROR]com/service/impl/ServiceImpl.java.java:[23,29] annotation
> values must be of the form 'name=value'
>
>
> On Sat, Feb 28, 2009 at 11:30 AM, Sergey Beryozkin
> <[email protected]> wrote:
>> Hi,
>> You can do something like
>>
>> @Produces("application/xml", "application/json")
>> public SomeType get() {}
>>
>> Cheers, Sergey
>>
>> -----Original Message-----
>> From: hanasaki jiji [mailto:[email protected]]
>> Sent: 28 February 2009 09:24
>> To: [email protected]
>> Subject: JAXRS : howto produce XML and JSON?
>>
>> How would you go about creating a jaxrs that can produce both JSON and
>> XML based on what the caller wants? Do you really need to write the
>> class twice and annotate each differently?
>>
>
>
--
View this message in context:
http://www.nabble.com/JAXRS-%3A-howto-produce-XML-and-JSON--tp22260215p22469511.html
Sent from the cxf-user mailing list archive at Nabble.com.