LnkedTreeMap нельзя привести к ошибке - PullRequest
0 голосов
/ 30 мая 2018

enter image description here

Вот мой код

@ Test

public void getAllEmployeesTest() throws IOException {
    HttpResponse response = http.get("http://localhost:8087/employee");
    List<Employee> expectedList = new ArrayList<Employee>();
    expectedList.add(new Employee(2, "Yashwant", "Chavan", 30, true));
    Type listType = new TypeToken<ArrayList<Employee>>() {
    }.getType();
    List<Employee> actualList = gson.fromJson(EntityUtils.toString(response.getEntity()), new ArrayList<Employee>().getClass());
    //Assert.assertEquals(actualList, expectedList);
    System.out.println(expectedList.get(0).isBusy());
    System.out.println(actualList.get(0).isBusy());
}

1 Ответ

0 голосов
/ 30 мая 2018

Вы можете десериализовать его следующим фрагментом кода

Type typeToken = new TypeToken<ArrayList<Employee>>(){}.getType();
List<Employee> actualList = gson.fromJson(EntityUtils.toString(response.getEntity()), typeToken);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...