users@jersey.java.net

Re: boolean return values in a json mime type

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 23 Apr 2008 11:51:13 +0200

Hi Arul,

Glad you solve it. Jersey and JAX-RS do not support the reading/writing
of primitive types for entities. The main reason is it is simply not
clear in general what the serialization format for such primitive types
should be.

You could add your own message body writer for Boolean (see the
EntityProvider example distributed with Jersey), but IMHO conversion to
a String works just fine for such cases.

Paul.

Arul Dhesiaseelan wrote:
> Arul Dhesiaseelan wrote:
>> Hello,
>>
>> I have the following rest method which returns a boolean json response.
>>
>> @GET @Path("/isValid/{id}")
>> @ProduceMime({"application/json"})
>> public boolean isValid(@PathParam("id") String id) {
>> return true;
>> }
>>
>> But, it fails with the following error.
>>
>> SEVERE: A message body writer for Java type, class java.lang.Boolean,
>> and MIME m
>> edia type, application/json, was not found
>>
>> Am I missing any jars specific to this error? I have jettison in my
>> classpath.
>>
>> Thank you
>> Arul
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>> _________________________________________________
>> Scanned by MessageLabs for the Super Flux Friends
>> _________________________________________________
> I was able to fix this just by changing the return type as below.
>
> @GET @Path("/isValid/{id}")
> @ProduceMime({"application/json"})
> public String isValid(@PathParam("id") String id) {
> return new Boolean(true).toString();
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109