users@jersey.java.net

[Jersey] Re: Jersey 1.17 - JerseyTest vs Json

From: Tatu Saloranta <tsaloranta_at_gmail.com>
Date: Wed, 12 Jun 2013 15:31:58 -0700

Or, in general a POJO -- JAXB is one of beans. @XmlRootElement is only
needed with JAXB beans, but not with POJO mapping with Jackson.

Regardless, valid JSON must be an Object or Array; root level scalar values
are not legal JSON (unless newer JSON specification allows that -- this is
being debated right now).

-+ Tatu +-


On Wed, Jun 12, 2013 at 1:04 AM, Michal Gajdos <michal.gajdos_at_oracle.com>wrote:

> Hi,
>
> you cannot return a simple boolean value from a resource method if you
> want it to be serialized into Json (this wouldn't produce a valid Json).
> You need to return a JAXB bean from your method, like:
>
> @XmlRootElement
> public class TestBean {
>
> private boolean value;
>
> // create getters and setters
> }
>
> To learn more about the Json support in Jersey, see:
> https://jersey.java.net/nonav/documentation/1.17/json.html
>
> Michal
>
>
> On 12.06.2013 09:24 , pub cog wrote:
>
> Hi,
>
> I'm trying to use JerseyTest (v1.17) as describe here:
> https://jersey.java.net/nonav/documentation/1.17/test-framework.html
>
> But I keep getting this error:
>
> A message body writer for Java class java.lang.Boolean, and Java type
> class java.lang.Boolean, and MIME media type application/json was not found
> I made a simple and basic sample projet to reproduce this issue here:
> https://github.com/francisoud/jersey
>
> Could you take a look at it please.
> I must be missing something obvious ?!
>
> Thanks in advance
>
>
>
>
>