问题来自杰克逊。如果没有足够的信息反序列化到哪个类,则使用
linkedHashMap。
既然你不通知你的元素类型的杰克逊
ArrayList,它不知道你要反序列化到
ArrayList的
Account秒。因此,它恢复为默认值。
相反,您可能可以使用
as(JsonNode.class),然后
ObjectMapper以比保证价格允许的方式丰富的方式进行处理。像这样:
ObjectMapper mapper = new ObjectMapper();JsonNode accounts = given().when().expect().statusCode(expectedResponseCode) .get("accounts/" + newClub.getOwner().getCustId() + "/clubs") .as(JsonNode.class);//Jackson's use of generics here are completely unsafe, but that's another issueList<Account> accountList = mapper.convertValue( accounts, new TypeReference<List<Account>>(){});assertThat(accountList.get(0).getId()).isEqualTo(expectedId);


