Я пытаюсь достичь конечной точки Spring REST в другом модуле приложения. Итак, я пытаюсь использовать шаблон REST, чтобы получить список пользователей, как показано ниже:
Запрос API с использованием шаблона REST:
public List getUsersBySignUpType(String type, String id) {
String adminApiUrl = adminApiBaseUrl+"/crm/v1/users/?type="+type+"&id="+id;
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(org.springframework.http.MediaType.APPLICATION_JSON);
HttpEntity entity = new HttpEntity(headers);
ResponseEntity response = restTemplate.exchange(
adminApiUrl, HttpMethod.GET, entity, LeadUserList.class);
return response.getBody().getUsersList();
}
Класс LeadUserList:
public class LeadUserList {
private List usersList;
public List getUsersList() {
return usersList;
}
}
Класс модели LeadUser:
public class LeadUser {
@JsonProperty("id")
private String id;
@JsonProperty("email")
private String email;
@JsonProperty("name")
private String name;
@JsonProperty("businessName")
private String businessName;
@JsonProperty("phone")
private String phone;
@JsonProperty("address")
private String address;
@JsonProperty("createdTime")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private Date createdTime;
@JsonProperty("updatedTime")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private Date updatedTime;
@JsonProperty("bookletSignups")
private BookletSignUp bookletSignUp;
@JsonProperty("eventSignups")
private EventSignUp eventSignUp;
@JsonProperty("infoSignups")
private InfoSignUp infoSignUp;
@JsonProperty("webinarSignups")
private WebinarSignUp webinarSignUp;
public LeadUser() {
}
}
Класс контроллера конечных точек API:
@Controller
@Component
@RequestMapping(path = "/crm/v1")
public class UserController {
@Autowired
UserService userService;
@RequestMapping(value = "/users", method = GET,produces = "application/json")
@ResponseBody
public ResponseEntity getPartnersByDate(@RequestParam("type") String type,
@RequestParam("id") String id) throws ParseException {
List usersList = userService.getUsersByType(type);
return new ResponseEntity(usersList, HttpStatus.OK);
}
}
Хотя тип возвращаемого значения — JSON от конечной точки API, я получаю вышеуказанное исключение. Что я здесь сделал не так?
Исключение:
Could not extract response: no suitable HttpMessageConverter found for response type [class admin.client.domain.LeadUserList] and content type [application/json]
Подробнее здесь: https://stackoverflow.com/questions/559 ... type-appli
Не найден подходящий HttpMessageConverter для типа ответа и типа контента. Возникает исключение [application/json;charse ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение