Java Code Examples for org.springframework.http.converter.json.MappingJacksonValue#setFilters()

The following examples show how to use org.springframework.http.converter.json.MappingJacksonValue#setFilters() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractJackson2View.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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);
		if (serializationView != null) {
			container.setSerializationView(serializationView);
		}
		if (filters != null) {
			container.setFilters(filters);
		}
		value = container;
	}
	return value;
}
 
Example 2
Source File: AbstractJackson2View.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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);
		if (serializationView != null) {
			container.setSerializationView(serializationView);
		}
		if (filters != null) {
			container.setFilters(filters);
		}
		value = container;
	}
	return value;
}
 
Example 3
Source File: AbstractJackson2View.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: AbstractJackson2View.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 5
Source File: PageResource.java    From bonita-ui-designer with GNU General Public License v2.0 5 votes vote down vote up
@RequestMapping(value = "/{pageId}", method = RequestMethod.GET)
public MappingJacksonValue get(@PathVariable("pageId") String pageId)
        throws NotFoundException, RepositoryException {
    Page page = pageService.get(pageId);
    page.setAssets(assetVisitor.visit(page));

    FilterProvider filters = new SimpleFilterProvider()
            .addFilter("valueAsArray", SimpleBeanPropertyFilter.serializeAllExcept("value"));
    MappingJacksonValue mapping = new MappingJacksonValue(page);
    mapping.setFilters(filters);

    return mapping;
}
 
Example 6
Source File: ResourceController.java    From osiam with MIT License 5 votes vote down vote up
protected MappingJacksonValue buildResponse(Object resource, String attributes) {

        MappingJacksonValue wrapper = new MappingJacksonValue(resource);
        if (!Strings.isNullOrEmpty(attributes)) {
            Set<String> attributesSet = extractAttributes(attributes);
            FilterProvider filterProvider = new SimpleFilterProvider().addFilter(
                    "attributeFilter", SimpleBeanPropertyFilter.filterOutAllExcept(attributesSet)
            );
            wrapper.setFilters(filterProvider);
        }
        return wrapper;
    }
 
Example 7
Source File: FilteringController.java    From in28minutes-spring-microservices with MIT License 3 votes vote down vote up
@GetMapping("/filtering")
public MappingJacksonValue retrieveSomeBean() {
	SomeBean someBean = new SomeBean("value1", "value2", "value3");

	SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("field1", "field2");

	FilterProvider filters = new SimpleFilterProvider().addFilter("SomeBeanFilter", filter);

	MappingJacksonValue mapping = new MappingJacksonValue(someBean);

	mapping.setFilters(filters);

	return mapping;
}
 
Example 8
Source File: FilteringController.java    From in28minutes-spring-microservices with MIT License 3 votes vote down vote up
@GetMapping("/filtering-list")
public MappingJacksonValue retrieveListOfSomeBeans() {
	List<SomeBean> list = Arrays.asList(new SomeBean("value1", "value2", "value3"),
			new SomeBean("value12", "value22", "value32"));

	SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("field2", "field3");

	FilterProvider filters = new SimpleFilterProvider().addFilter("SomeBeanFilter", filter);

	MappingJacksonValue mapping = new MappingJacksonValue(list);

	mapping.setFilters(filters);

	return mapping;
}
 
Example 9
Source File: FilteringController.java    From spring-web-services with MIT License 3 votes vote down vote up
@GetMapping("/filtering")
public MappingJacksonValue retrieveSomeBean() {
	SomeBean someBean = new SomeBean("value1", "value2", "value3");

	SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("field1", "field2");

	FilterProvider filters = new SimpleFilterProvider().addFilter("SomeBeanFilter", filter);

	MappingJacksonValue mapping = new MappingJacksonValue(someBean);

	mapping.setFilters(filters);

	return mapping;
}
 
Example 10
Source File: FilteringController.java    From spring-web-services with MIT License 3 votes vote down vote up
@GetMapping("/filtering-list")
public MappingJacksonValue retrieveListOfSomeBeans() {
	List<SomeBean> list = Arrays.asList(new SomeBean("value1", "value2", "value3"),
			new SomeBean("value12", "value22", "value32"));

	SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("field2", "field3");

	FilterProvider filters = new SimpleFilterProvider().addFilter("SomeBeanFilter", filter);

	MappingJacksonValue mapping = new MappingJacksonValue(list);

	mapping.setFilters(filters);

	return mapping;
}
 
Example 11
Source File: FilteringController.java    From spring-microservices with MIT License 3 votes vote down vote up
@GetMapping("/filtering")
public MappingJacksonValue retrieveSomeBean() {
	SomeBean someBean = new SomeBean("value1", "value2", "value3");

	SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("field1", "field2");

	FilterProvider filters = new SimpleFilterProvider().addFilter("SomeBeanFilter", filter);

	MappingJacksonValue mapping = new MappingJacksonValue(someBean);

	mapping.setFilters(filters);

	return mapping;
}
 
Example 12
Source File: FilteringController.java    From spring-microservices with MIT License 3 votes vote down vote up
@GetMapping("/filtering-list")
public MappingJacksonValue retrieveListOfSomeBeans() {
	List<SomeBean> list = Arrays.asList(new SomeBean("value1", "value2", "value3"),
			new SomeBean("value12", "value22", "value32"));

	SimpleBeanPropertyFilter filter = SimpleBeanPropertyFilter.filterOutAllExcept("field2", "field3");

	FilterProvider filters = new SimpleFilterProvider().addFilter("SomeBeanFilter", filter);

	MappingJacksonValue mapping = new MappingJacksonValue(list);

	mapping.setFilters(filters);

	return mapping;
}