The issue's coming from Jackson. When it doesn't have enough information on what class to deserialize to, it uses LinkedHashMap
.
Since you're not informing Jackson of the element type of your ArrayList
, it doesn't know that you want to deserialize into an ArrayList
of Account
s. So it falls back to the default.
Instead, you could probably use as(JsonNode.class)
, and then deal with the ObjectMapper
in a richer manner than rest-assured allows. Something like this:
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 issue
List<Account> accountList = mapper.convertValue(
accounts,
new TypeReference<List<Account>>(){}
);
assertThat(accountList.get(0).getId()).isEqualTo(expectedId);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…