Search in sources :

Example 1 with JsonViewRequestBodyAdvice

use of org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice in project spring-framework by spring-projects.

the class WebMvcConfigurationSupport method requestMappingHandlerAdapter.

/**
	 * Returns a {@link RequestMappingHandlerAdapter} for processing requests
	 * through annotated controller methods. Consider overriding one of these
	 * other more fine-grained methods:
	 * <ul>
	 * <li>{@link #addArgumentResolvers} for adding custom argument resolvers.
	 * <li>{@link #addReturnValueHandlers} for adding custom return value handlers.
	 * <li>{@link #configureMessageConverters} for adding custom message converters.
	 * </ul>
	 */
@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
    RequestMappingHandlerAdapter adapter = createRequestMappingHandlerAdapter();
    adapter.setContentNegotiationManager(mvcContentNegotiationManager());
    adapter.setMessageConverters(getMessageConverters());
    adapter.setWebBindingInitializer(getConfigurableWebBindingInitializer());
    adapter.setCustomArgumentResolvers(getArgumentResolvers());
    adapter.setCustomReturnValueHandlers(getReturnValueHandlers());
    if (jackson2Present) {
        adapter.setRequestBodyAdvice(Collections.singletonList(new JsonViewRequestBodyAdvice()));
        adapter.setResponseBodyAdvice(Collections.singletonList(new JsonViewResponseBodyAdvice()));
    }
    AsyncSupportConfigurer configurer = new AsyncSupportConfigurer();
    configureAsyncSupport(configurer);
    if (configurer.getTaskExecutor() != null) {
        adapter.setTaskExecutor(configurer.getTaskExecutor());
    }
    if (configurer.getTimeout() != null) {
        adapter.setAsyncRequestTimeout(configurer.getTimeout());
    }
    adapter.setCallableInterceptors(configurer.getCallableInterceptors());
    adapter.setDeferredResultInterceptors(configurer.getDeferredResultInterceptors());
    return adapter;
}
Also used : JsonViewRequestBodyAdvice(org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice) JsonViewResponseBodyAdvice(org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) Bean(org.springframework.context.annotation.Bean)

Example 2 with JsonViewRequestBodyAdvice

use of org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice in project spring-framework by spring-projects.

the class TestPathHelper method verifyRequestResponseBodyAdvice.

@SuppressWarnings("unchecked")
private void verifyRequestResponseBodyAdvice(Object bean) {
    assertNotNull(bean);
    Object value = new DirectFieldAccessor(bean).getPropertyValue("requestResponseBodyAdvice");
    assertNotNull(value);
    assertTrue(value instanceof List);
    List<ResponseBodyAdvice> converters = (List<ResponseBodyAdvice>) value;
    assertTrue(converters.get(0) instanceof JsonViewRequestBodyAdvice);
    assertTrue(converters.get(1) instanceof JsonViewResponseBodyAdvice);
}
Also used : JsonViewResponseBodyAdvice(org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice) ResponseBodyAdvice(org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice) JsonViewRequestBodyAdvice(org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JsonViewResponseBodyAdvice(org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice) List(java.util.List)

Aggregations

JsonViewRequestBodyAdvice (org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice)2 JsonViewResponseBodyAdvice (org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice)2 List (java.util.List)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 Bean (org.springframework.context.annotation.Bean)1 RequestMappingHandlerAdapter (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter)1 ResponseBodyAdvice (org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice)1