ArrayLimitingJsonContentModifier extends JsonContentModifier { @Override protected void modifyJson(JsonNode root) { walk(root, arraysOnly(), shortenArray(3)); } protected  ArrayLimitingJsonContentModifier(ObjectMapper objectMapper);   }
@Test public void testModifyJsonWithMoreThanThreeItems() throws Exception { ObjectMapper mapper = new ObjectMapper(); ArrayLimitingJsonContentModifier modifier = new ArrayLimitingJsonContentModifier(mapper); WithArray object = WithArray.withItems(100); JsonNode root = mapper.readTree(mapper.writeValueAsString(object)); modifier.modifyJson(root); assertThat(root.get("items")).hasSize(3); assertThat(root.get("ignore").isNumber()).isTrue(); }
@Test public void testModifyJsonWithLessThanThreeItems() throws Exception { ObjectMapper mapper = new ObjectMapper(); ArrayLimitingJsonContentModifier modifier = new ArrayLimitingJsonContentModifier(mapper); WithArray object = WithArray.withItems(2); JsonNode root = mapper.readTree(mapper.writeValueAsString(object)); modifier.modifyJson(root); assertThat(root.get("items")).hasSize(2); assertThat(root.get("ignore").isNumber()).isTrue(); }