Java.lang.IllegalStateException: ожидалось BEGIN_OBJECT, но было STRING в строке 1, столбец 67, путь $.data [дубликат]JAVA

Программисты 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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»