I'm using DropWizard with jersey to make a client that accepts JSON from a server and maps it to a POJO. However, I get this error when invoking the client.
java.lang.IllegalArgumentException: Error parsing media type 'application/json;encoding=utf8, charset=utf-8'
My code is as follows:
@Path("/something")
@Produces(MediaType.APPLICATION_JSON)
public class SampleClient {
final Client client;
WebResource.Builder builder;
public SampleClient (Client client) {
this.client = client;
this.builder = client.resource("http://localhost/mysample/service").type("application/json");
}
@GET
public MyMapper getSomething() {
MyMapper result = builder.accept("application/json").get(MyMapper.class);
return result;
}
}
What am I doing wrong?
Are you generating that header in your client?
According to W3C - 4 The Content-Type Header Field the Content-type header must have the format:
Content-Type := type "/" subtype *[";" parameter]
where
parameter := attribute "=" value
So you could have as a parseable media type:
Content-type: application/json; encoding=utf8; charset=utf8
Using a semicolon instead of a comma. This doesn't mean it's correct, just parseable. Try using instead:
Content-type: application/json; charset=utf8
If that's a client error, then you might need to configure an Accept header (and the Content-type is not necessary since you aren't sending any payload). Try it without specifying the charset (if it fails, it will fail for another reason). You can test different headers and encodings using an interactive REST client, such as the Firefox REST client
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With