Bare literals (number, boolean, string, null) is not recommended as
application/json payload, try an object {"myInt": 17} or an array [17]
instead.
On Mon, Jul 21, 2014 at 9:26 AM, Tomaz Majerhold <tomaz.majerhold_at_arnes.si>
wrote:
> I have problem to read REST Integer response with jersey client, but if I
> try with browser it display it correctly.
>
>
> 1) server side:
>
> maven:
> -----------
> <dependency>
> <groupId>com.sun.jersey</groupId>
> <artifactId>jersey-json</artifactId>
> <version>1.18.1</version>
> </dependency>
>
> rest:
> ----------
> @Path("/int")
> @GET
> @Produces({"application/json"})
> public Integer getInt();
>
> And in javax.ws.rs.core.Application I add JacksonJsonProvider.class
>
> 2) client side:
>
> maven:
> -----------
> <dependency>
> <groupId>com.sun.jersey</groupId>
> <artifactId>jersey-json</artifactId>
> <version>1.18.1</version>
> </dependency>
> <dependency>
> <groupId>com.sun.jersey</groupId>
> <artifactId>jersey-json</artifactId>
> <version>1.18.1</version>
> </dependency>
>
> rest:
> ----------
> ClientResponse clientResponse = webResource
> .path(PATH_BASIC+"/"+"int")
> .accept("application/json")
> .get(ClientResponse.class);
>
> testInt = clientResponse.getEntity(Integer.class);
>
> HTTP Header:
> ------------------
> GET /aai-api-server/rest/wc/int HTTP/1.1
> Accept: application/json
> Authorization: Basic Ymxhei5kaXZqYWtAYXJuZXMuc2k6Ym
> xhei5kaXZqYWtAYXJuZXMuc2k=
> Cache-Control: no-cache
> Pragma: no-cache
> User-Agent: Java/1.7.0_25
> Host: localhost:8181
> Connection: keep-alive
>
>
> Error:
> ----------
> com.sun.jersey.api.client.ClientHandlerException: A message body reader
> for Java class java.lang.Integer, and Java type class java.lang.Integer,
> and MIME media type text/html; charset=ISO-8859-1 was not found
>
>
> What I'm doing wrong?
>
> Regards, Tomaz
>
--
Mikael Ståldal
Chief Software Architect
*Appear*
Phone: +46 8 545 91 572
Email: mikael.staldal_at_appearnetworks.com