I have this code :
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class Application {
public static void main(String args[]) {
SpringApplication.run(Application.class);
}
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
RestTemplate restTemplate = builder.rootUri("http://login.xxx.com/").basicAuthorization("user", "pass").build();
return restTemplate;
}
@Bean
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
return args -> {
restTemplate.getForObject(
"http://login.xxx.com/ws/YY/{id}", YY.class,
"123");
};
}
}
but I'm getting this error : Caused by: org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.xxx.test.YY] and content type [application/xml;charset=ISO-8859-1]
How can I add MediaType.APPLICATION_JSON to the header and add the header to the restTemplate and do getForObject ?