MappingJacksonJsonView extends MappingJackson2JsonView { boolean isFilterNeeded(Map<String, Object> model) { Set<String> renderedAttributes = (!CollectionUtils.isEmpty(getModelKeys()) ? getModelKeys() : model.keySet()); for (Map.Entry<String, Object> entry : model.entrySet()) { if (!(entry.getValue() instanceof BindingResult) && renderedAttributes.contains(entry.getKey())) { return true; } } return false; } MappingJacksonJsonView();   }
@Test public void testIsFilterNeeded() throws Exception { MappingJacksonJsonView view = new MappingJacksonJsonView(); view.setModelKey("response"); Assert.assertTrue(view.isFilterNeeded(groovyMap("[response:[data:['foo','bar']]]"))); Assert.assertTrue(view.isFilterNeeded(groovyMap("[response:[data:['foo','bar']], boo:['baa']]"))); Assert.assertFalse(view.isFilterNeeded(groovyMap("[request:[data:['foo','bar']], boo:['baa']]"))); Assert.assertFalse(view.isFilterNeeded(groovyMap("[data:[response:['foo','bar']]]"))); }