use of com.fasterxml.jackson.databind.ser.FilterProvider in project spring-framework by spring-projects.
the class AbstractJackson2View method filterAndWrapModel.
/**
* Filter and optionally wrap the model in {@link MappingJacksonValue} container.
* @param model the model, as passed on to {@link #renderMergedOutputModel}
* @param request current HTTP request
* @return the wrapped or unwrapped value to be rendered
*/
protected Object filterAndWrapModel(Map<String, Object> model, HttpServletRequest request) {
Object value = filterModel(model);
Class<?> serializationView = (Class<?>) model.get(JsonView.class.getName());
FilterProvider filters = (FilterProvider) model.get(FilterProvider.class.getName());
if (serializationView != null || filters != null) {
MappingJacksonValue container = new MappingJacksonValue(value);
container.setSerializationView(serializationView);
container.setFilters(filters);
value = container;
}
return value;
}
use of com.fasterxml.jackson.databind.ser.FilterProvider in project spring-framework by spring-projects.
the class MappingJackson2JsonViewTests method renderSimpleBeanWithFilters.
@Test
public void renderSimpleBeanWithFilters() throws Exception {
TestSimpleBeanFiltered bean = new TestSimpleBeanFiltered();
bean.setProperty1("value");
bean.setProperty2("value");
Map<String, Object> model = new HashMap<>();
model.put("bindingResult", mock(BindingResult.class, "binding_result"));
model.put("foo", bean);
FilterProvider filters = new SimpleFilterProvider().addFilter("myJacksonFilter", SimpleBeanPropertyFilter.serializeAllExcept("property2"));
model.put(FilterProvider.class.getName(), filters);
view.setUpdateContentLength(true);
view.render(model, request, response);
String content = response.getContentAsString();
assertTrue(content.length() > 0);
assertEquals(content.length(), response.getContentLength());
assertThat(content, containsString("\"property1\":\"value\""));
assertThat(content, not(containsString("\"property2\":\"value\"")));
assertFalse(content.contains(FilterProvider.class.getName()));
}
use of com.fasterxml.jackson.databind.ser.FilterProvider in project jackson-databind by FasterXML.
the class TestAnyGetterFiltering method testAnyGetterFiltering.
/*
/**********************************************************
/* Test methods
/**********************************************************
*/
public void testAnyGetterFiltering() throws Exception {
ObjectMapper mapper = new ObjectMapper();
FilterProvider prov = new SimpleFilterProvider().addFilter("anyFilter", SimpleBeanPropertyFilter.filterOutAllExcept("b"));
assertEquals("{\"b\":\"2\"}", mapper.writer(prov).writeValueAsString(new AnyBean()));
}
use of com.fasterxml.jackson.databind.ser.FilterProvider in project jackson-databind by FasterXML.
the class TestJsonFilter method testIncludeAllFilter.
public void testIncludeAllFilter() throws Exception {
FilterProvider prov = new SimpleFilterProvider().addFilter("RootFilter", SimpleBeanPropertyFilter.serializeAll());
assertEquals("{\"a\":\"a\",\"b\":\"b\"}", MAPPER.writer(prov).writeValueAsString(new Bean()));
}
use of com.fasterxml.jackson.databind.ser.FilterProvider in project jackson-databind by FasterXML.
the class TestJsonFilter method testFilterOnProperty.
// Wrt [Issue#306]
public void testFilterOnProperty() throws Exception {
FilterProvider prov = new SimpleFilterProvider().addFilter("RootFilter", SimpleBeanPropertyFilter.filterOutAllExcept("a")).addFilter("b", SimpleBeanPropertyFilter.filterOutAllExcept("b"));
assertEquals("{\"first\":{\"a\":\"a\"},\"second\":{\"b\":\"b\"}}", MAPPER.writer(prov).writeValueAsString(new FilteredProps()));
}
Aggregations