Die API -Anforderung mit REST -Vorlage: < /p>
Code: Select all
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();
}
< /code>
LeaduserList -Klasse: < /p>
public class LeadUserList {
private List usersList;
public List getUsersList() {
return usersList;
}
}
< /code>
Bleimodellklasse: < /p>
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() {
}
}
< /code>
Die API -Endpunkt -Controller -Klasse: < /p>
@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);
}
}
< /code>
Obwohl der Rückgabetyp JSON aus dem API -Endpunkt ist, erhalten Sie die obige Ausnahme. Was habe ich hier falsch gemacht? < /p>
Die Ausnahme: < /p>
Could not extract response: no suitable HttpMessageConverter found for response type [class admin.client.domain.LeadUserList] and content type [application/json]