team,
here is my rest server code:
@POST
@Path("/example3")
@Consumes("application/json")
@Produces({"application/json"})
public Response example3(Example example) throws JsonProcessingException {
try{
example.setFoo("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
System.out.println(example);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}catch(Exception e){
}
return Response.status(Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON).entity("FOOBAR").build();
}
client code:
@Test
public void postJerseyTest7() throws JsonParseException,
JsonMappingException, IOException {
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target("
http://localhost:8080/hello-world");
Example example = new Example(7, "foo");
Response response = target
.path("example3")
.request()
.accept(MediaType.APPLICATION_JSON)
.post(Entity.entity(example, MediaType.APPLICATION_JSON),
Response.class);
System.out.println("Response: " + response);
System.out.println("entity: " + response.getEntity());
}
yields:
Response: InboundJaxrsResponse{context=ClientResponse{method=POST, uri=
http://localhost:8080/hello-world/example3, status=400, reason=Bad Request}}
entity: org.glassfish.jersey.client.internal.HttpUrlConnector$2@43a2dab4
why is my entity not FOOBAR?
many thanks,
mp