Closed FrelliBB closed 7 years ago
I don't really agree with this. This is by design. You're not meant to have any content-type when the body is empty (more so, when sending a GET request since there's no entity).
The flaw, in this case, is in the server. In fact, the request data and bind()
have nothing to do with each other since bind()
deals with the response. The server is choosing to send data depending on the request's Content-type
. If you really want to set the content-type on a request containing no body then I feel like GeneralRequest.get(url).setContentType("application/json")
is enough.
In the HTTP standard, the expected response type is usually specified using the Accept
header.
Turns out this was actually a bug in my code where I had a @Consumes("application/json")
on a @GET
method! My server was sending a 415 Unsupported Media Type
error and thus the .bind()
was failing.
However this does uncover the issue that if .bind()
fails, the response that the server sent is not logged anywhere. I did not realise at any point that my server was sending a 415
.
Opened a separate issue for this here https://github.com/bastion-dev/Bastion/issues/73
JsonRequest requires a
JsonRequest.get(url)
utility method which functions the same way asGeneralRequest.get()
but sets the content type toapplication/json
.This will also allow the .bind() to properly decode the model of the response from the GET into its json representation. The current alternative to this is using
GeneralRequest.get(url).setContentType("application/json")
.