I approached him by creating an ApiClient instance in the application class and installing a custom REST template.
In my case, I used Json message conversion for Jackson:
RestTemplate restTemplate = new RestTemplate(fac); MappingJacksonHttpMessageConverter converter = new MappingJacksonHttpMessageConverter(); converter.getObjectMapper().configure(Feature.UNWRAP_ROOT_VALUE, true); restTemplate .getMessageConverters() .add(converter); mClient.setRestTemplate(restTemplate);
My factory fac query is as follows:
ClientHttpRequestFactory fac = new HttpComponentsClientHttpRequestFactory() { @Override protected HttpUriRequest createHttpRequest(HttpMethod httpMethod, URI uri) { HttpUriRequest uriRequest = super.createHttpRequest(httpMethod, uri); // Add request headers uriRequest.addHeader( "Content-Type", MediaType.APPLICATION_JSON_VALUE); return uriRequest; } @Override public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IOException { if (Config.DEBUG_REQUESTS) { Log.d(TAG, uri); } return super.createRequest(uri, httpMethod); } };
A WARNING
Although this works on all Android devices in our office, I recently discovered that headers do not appear with all devices! I'm not sure why this (or the device), but I search in it and try to update this answer when I find permission.
source share