新建自定义转换器
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import java.util.ArrayList;
import java.util.List;
/**
* @author Susinl
*/
public class MyMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter {
public MyMappingJackson2HttpMessageConverter(){
List<MediaType> mediaTypes = new ArrayList<>();
mediaTypes.add(MediaType.ALL);
setSupportedMediaTypes(mediaTypes);
}
}
HttpClient.java中调用
Integer finalTimeOut = 300000;
CloseableHttpClient httpClient = HttpClientUtils.acceptsUntrustedCertsHttpClient();
HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
clientHttpRequestFactory.setConnectTimeout(60000);
clientHttpRequestFactory.setReadTimeout(finalTimeOut);
RestTemplate restTemplate = new RestTemplate(clientHttpRequestFactory);
restTemplate.getMessageConverters().add(new MyMappingJackson2HttpMessageConverter());