I have following code structure : Config.java
public class Config {
private Map<Context, Set<String>> mapStrings;
public Map<Context, Set<String>> getMapStrings() {
return mapStrings;
}
public void setMapStrings(Map<Context, Set<String>> mapStrings) {
this.mapStrings = mapStrings;
}
public static class Context {
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
controller code :
@RestController("somepath")
@RequestMapping("someMapping")
public class ConfigurationController{
@GetMapping("")
public Config get(){
Config config = new Config();
return config;
}
}
Test code :
TestRestTemplate restTemplate
@Test
public void test(){
String url="url";
ResponseEntity<Config> response = restTemplate.exchange(
String.format(url), HttpMethod.GET, null,
Config.class);
assertNotNull(response);
}
pom.xml
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
Now in spite of having jackson-databind dependency in my pom, I am getting this error :
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class Config] and content type [application/json;charset=UTF-8]
I understand this error is because of the Map that I have used in my config.java. If I convert this map to Map> then it goes away. so for some reason it is not able to convert my custom class Context to json. Can somebody help ? I am using spring-boot. I would preferably like to use some spring/jackson provided http message converter instead of writing my own.