Note that there are some explanatory texts on larger screens.

plurals
  1. POJAX-RS / Jersey ".get(Integer.class)" and single JSON primitive (Integer) values?
    primarykey
    data
    text
    <p>I have a JAX-RS WebService with the following method:</p> <pre><code>@Path("/myrest") public class MyRestResource { ... @GET @Path("/getInteger") @Produces(APPLICATION_JSON) public Integer getInteger() { return 42; } </code></pre> <p>When accessed using this snipped:</p> <pre><code>@Test public void testGetPrimitiveWrapers() throws IOException { // this works: assertEquals(new Integer(42), new ObjectMapper().readValue("42", Integer.class)); // that fails: assertEquals(new Integer(42), resource().path("/myrest/getInteger").get(Integer.class)); } </code></pre> <p>I get the following exception:</p> <pre><code>com.sun.jersey.api.client.ClientResponse getEntity SEVERE: A message body reader for Java class java.lang.Integer, and Java type class java.lang.Integer, and MIME media type application/json was not found com.sun.jersey.api.client.ClientResponse getEntity SEVERE: The registered message body readers compatible with the MIME media type are: application/json ... </code></pre> <p>The problem is just with returning single primitive values (int/boolean) or their wrapper classes. Returning other POJO classes is not the problemen so I guess all the answers regarding JSONConfiguration.FEATURE_POJO_MAPPING and JAXB annotations do not apply here. Or which annotation should I use to describe the return type if I don't have access to its class source?</p> <p>Using ngrep I can verify that just the String "42" is returned by the webservice. Thats a valid JSON "value" but not a valid JSON "text" according to the spec. So is my problem on the client or the server side?</p> <p>I tried activating JSONConfiguration natural/badgerfish according to <a href="http://tugdualgrall.blogspot.de/2011/09/jax-rs-jersey-and-single-element-arrays.html" rel="nofollow">http://tugdualgrall.blogspot.de/2011/09/jax-rs-jersey-and-single-element-arrays.html</a> but with no success (ngrep still shows just "42"). Would that be the right path?</p> <p>Any ideas are appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload