I have this method and I have a problem with gson in code :
Код: Выделить всё
public static CmsUser validateTokenCms(String token, RestTemplate restTemplate, PropertyCommonConfig propertyCommonConfig) { TokenRequest tokenRequest = new TokenRequest(); tokenRequest.setChannel("ORDER_RUNTIME"); tokenRequest.setTransid(UUID.randomUUID().toString().replace("-", "").substring(0, 10)); tokenRequest.setToken(token); String authString = propertyCommonConfig.getUserNameAuth() + ":" + propertyCommonConfig.getPasswordAuth(); String encodedAuthString = Base64.getEncoder().encodeToString(authString.getBytes(StandardCharsets.UTF_8)); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + encodedAuthString); headers.add("Content-Type", "application/json"); HttpEntity entity = new HttpEntity(tokenRequest, headers); ResponseEntity responseEntity = null; try { responseEntity = restTemplate.postForEntity(propertyCommonConfig.getUrlAuthen() + "/customer/checkTokenCms", entity, String.class); } catch (Exception e) { e.printStackTrace(); } log.info("====== responseEntity ======== " + responseEntity); Gson gson = new Gson(); CheckTokenResp response = gson.fromJson(responseEntity.getBody(), CheckTokenResp.class); log.info("====== response ======== " + response); if (response == null) return null; CmsUser cmsUser = response.getData(); log.info("====== cmsUser ======== " + cmsUser); if (cmsUser == null) return null; return cmsUser; } java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 67 path $.data
Источник: https://stackoverflow.com/questions/781 ... -at-line-1