Reputation:
in my web application I invoke a service like this:
Response response = null;
Builder builder = webTarget.request().accept(MediaType.APPLICATION_JSON_TYPE);
if (this.headers != null) {
builder.headers(this.headers); // headers is empty in this case
}
response = builder.method(methodName.toString(), Entity.entity(multiPart, multiPart.getMediaType()), Response.class);
if (typeOfT.equals(Response.class)) {
return (T) response;
} else {
handleException(response);
return gson.fromJson(response.readEntity(String.class), typeOfT);
}
The service responds correctly but when I try to deserialize the response, this exception is thrown:
org.glassfish.jersey.message.internal.HeaderValueException: Too many "Content-Type" header values: "[application/json; charset=utf-8, application/json]"
I use:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25.1</version>
</dependency>
Upvotes: 2
Views: 1168
Reputation: 209102
You will get this error when the response has more than one Content-Type
response header. What you can do id reset the header to just use one by using response.getHeaders().putSingle()
. This will override the double headers and just leave you with one.
response.getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
return gson.fromJson(response.readEntity(String.class), typeOfT);
Upvotes: 1