You can use RestTemplate with Gson or Jackson.
Gson is fine and easier to use, you have a small json dataset. Jackson is more suitable if you have a complex / deep json tree, because Gson creates a lot of temporary objects, which causes the global GC to stop.
The error here suggests that he cannot find an HttpMessageConverter capable of parsing application/octet-stream .
If you look at the sources of the GsonHttpMessageConverter , you will notice that it only supports the mimetype application/json .
This means that you have two options:
- Or return from your content that will match correctly
- Or just change the supported media types to
GsonHttpMessageConverter :
String json = "{\"param\":3}"; GsonHttpMessageConverter converter = new GsonHttpMessageConverter(); converter.setSupportedMediaTypes(new MediaType("application", "octet-stream", Charset.forName("UTF-8"))); restClient.getRestTemplate().getMessageConverters().add(converter); Response res = restClient.send(json);
source share