Программисты JAVA общаются здесь
-
Гость
Java.lang.IllegalStateException: ожидалось BEGIN_OBJECT, но было STRING в строке 1, столбец 67, путь $.data [дубликат]
Сообщение
Гость »
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; }
It shows the following error:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 67 path $.data
Источник:
https://stackoverflow.com/questions/781 ... -at-line-1
1709975678
Гость
I have this method and I have a problem with gson in code :
[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; } [/code] It shows the following error:
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 67 path $.data
Источник: [url]https://stackoverflow.com/questions/78131519/java-lang-illegalstateexception-expected-begin-object-but-was-string-at-line-1[/url]