Search in sources :

Example 1 with AbstractJackson2HttpMessageConverter

use of org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter in project nikita-noark5-core by HiOA-ABI.

the class AppWebMvcConfiguration method extendMessageConverters.

/**
     *  Allows us to pretty print JSON/XML output. CLI tools like curl may not prettyprint for you
     *  so this allows us to format the api output so that any developer testing the system gets nicely
     *  formatted output.
     *  However the client should be using Accept: application/json or application/xml when connecting
     */
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    final Optional<HttpMessageConverter<?>> jsonConverterFound = converters.stream().filter(c -> c instanceof MappingJackson2HttpMessageConverter).findFirst();
    if (jsonConverterFound.isPresent()) {
        final AbstractJackson2HttpMessageConverter converter = (AbstractJackson2HttpMessageConverter) jsonConverterFound.get();
        converter.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
        // Convert timestamps to readable text strings
        converter.getObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        converter.getObjectMapper().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    }
    final Optional<HttpMessageConverter<?>> xmlConverterFound = converters.stream().filter(c -> c instanceof MappingJackson2XmlHttpMessageConverter).findFirst();
    if (jsonConverterFound.isPresent()) {
        final MappingJackson2XmlHttpMessageConverter converter = (MappingJackson2XmlHttpMessageConverter) xmlConverterFound.get();
        converter.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
        converter.getObjectMapper().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    }
}
Also used : Ordered(org.springframework.core.Ordered) ViewResolver(org.springframework.web.servlet.ViewResolver) NikitaETAGInterceptor(no.arkivlab.hioa.nikita.webapp.web.interceptor.NikitaETAGInterceptor) VersionResourceResolver(org.springframework.web.servlet.resource.VersionResourceResolver) LocaleResolver(org.springframework.web.servlet.LocaleResolver) InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) SessionLocaleResolver(org.springframework.web.servlet.i18n.SessionLocaleResolver) EnableSpringDataWebSupport(org.springframework.data.web.config.EnableSpringDataWebSupport) CacheControl(org.springframework.http.CacheControl) org.springframework.web.servlet.config.annotation(org.springframework.web.servlet.config.annotation) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) TimeUnit(java.util.concurrent.TimeUnit) LocaleChangeInterceptor(org.springframework.web.servlet.i18n.LocaleChangeInterceptor) List(java.util.List) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Locale(java.util.Locale) Optional(java.util.Optional) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) Bean(org.springframework.context.annotation.Bean) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter)

Example 2 with AbstractJackson2HttpMessageConverter

use of org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter in project nikita-noark5-core by HiOA-ABI.

the class AppWebMvcConfiguration method extendMessageConverters.

/**
 *  Allows us to pretty print JSON/XML output. CLI tools like curl may not prettyprint for you
 *  so this allows us to format the api output so that any developer testing the system gets nicely
 *  formatted output.
 *  However the client should be using Accept: application/json or application/xml when connecting
 */
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    final Optional<HttpMessageConverter<?>> jsonConverterFound = converters.stream().filter(c -> c instanceof MappingJackson2HttpMessageConverter).findFirst();
    if (jsonConverterFound.isPresent()) {
        final AbstractJackson2HttpMessageConverter converter = (AbstractJackson2HttpMessageConverter) jsonConverterFound.get();
        converter.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
        // Convert timestamps to readable text strings
        converter.getObjectMapper().configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        converter.getObjectMapper().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    }
    final Optional<HttpMessageConverter<?>> xmlConverterFound = converters.stream().filter(c -> c instanceof MappingJackson2XmlHttpMessageConverter).findFirst();
    if (jsonConverterFound.isPresent()) {
        final MappingJackson2XmlHttpMessageConverter converter = (MappingJackson2XmlHttpMessageConverter) xmlConverterFound.get();
        converter.getObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
        converter.getObjectMapper().enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    }
}
Also used : PathMatchConfigurer(org.springframework.web.servlet.config.annotation.PathMatchConfigurer) VersionResourceResolver(org.springframework.web.servlet.resource.VersionResourceResolver) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) ResourceHandlerRegistry(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry) EnableSpringDataWebSupport(org.springframework.data.web.config.EnableSpringDataWebSupport) CacheControl(org.springframework.http.CacheControl) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) InterceptorRegistry(org.springframework.web.servlet.config.annotation.InterceptorRegistry) Optional(java.util.Optional) SerializationFeature(com.fasterxml.jackson.databind.SerializationFeature) NikitaETAGInterceptor(nikita.webapp.web.interceptor.NikitaETAGInterceptor) WebMvcConfigurer(org.springframework.web.servlet.config.annotation.WebMvcConfigurer) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter)

Example 3 with AbstractJackson2HttpMessageConverter

use of org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter in project spring-framework by spring-projects.

the class WebMvcConfigurationSupportTests method requestMappingHandlerAdapter.

@Test
public void requestMappingHandlerAdapter() {
    ApplicationContext context = initContext(WebConfig.class);
    RequestMappingHandlerAdapter adapter = context.getBean(RequestMappingHandlerAdapter.class);
    List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
    assertThat(converters.size()).isEqualTo(12);
    converters.stream().filter(converter -> converter instanceof AbstractJackson2HttpMessageConverter).forEach(converter -> {
        ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter) converter).getObjectMapper();
        assertThat(mapper.getDeserializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION)).isFalse();
        assertThat(mapper.getSerializationConfig().isEnabled(DEFAULT_VIEW_INCLUSION)).isFalse();
        assertThat(mapper.getDeserializationConfig().isEnabled(FAIL_ON_UNKNOWN_PROPERTIES)).isFalse();
        if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
            assertThat(mapper.getClass()).isEqualTo(XmlMapper.class);
        }
    });
    ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
    assertThat(initializer).isNotNull();
    ConversionService conversionService = initializer.getConversionService();
    assertThat(conversionService).isNotNull();
    boolean condition1 = conversionService instanceof FormattingConversionService;
    assertThat(condition1).isTrue();
    Validator validator = initializer.getValidator();
    assertThat(validator).isNotNull();
    boolean condition = validator instanceof LocalValidatorFactoryBean;
    assertThat(condition).isTrue();
    DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
    @SuppressWarnings("unchecked") List<Object> bodyAdvice = (List<Object>) fieldAccessor.getPropertyValue("requestResponseBodyAdvice");
    assertThat(bodyAdvice.size()).isEqualTo(2);
    assertThat(bodyAdvice.get(0).getClass()).isEqualTo(JsonViewRequestBodyAdvice.class);
    assertThat(bodyAdvice.get(1).getClass()).isEqualTo(JsonViewResponseBodyAdvice.class);
}
Also used : LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) PathVariable(org.springframework.web.bind.annotation.PathVariable) DefaultRequestToViewNameTranslator(org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator) DEFAULT_VIEW_INCLUSION(com.fasterxml.jackson.databind.MapperFeature.DEFAULT_VIEW_INCLUSION) Validator(org.springframework.validation.Validator) WebDataBinderFactory(org.springframework.web.bind.support.WebDataBinderFactory) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ModelAndViewContainer(org.springframework.web.method.support.ModelAndViewContainer) LocaleResolver(org.springframework.web.servlet.LocaleResolver) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) SessionFlashMapManager(org.springframework.web.servlet.support.SessionFlashMapManager) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) FAIL_ON_UNKNOWN_PROPERTIES(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) HandlerExceptionResolverComposite(org.springframework.web.servlet.handler.HandlerExceptionResolverComposite) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) Locale(java.util.Locale) Map(java.util.Map) MethodParameter(org.springframework.core.MethodParameter) AntPathMatcher(org.springframework.util.AntPathMatcher) LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean) JsonViewRequestBodyAdvice(org.springframework.web.servlet.mvc.method.annotation.JsonViewRequestBodyAdvice) AcceptHeaderLocaleResolver(org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) HandlerMethodArgumentResolver(org.springframework.web.method.support.HandlerMethodArgumentResolver) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) ISO(org.springframework.format.annotation.DateTimeFormat.ISO) StaticMessageSource(org.springframework.context.support.StaticMessageSource) Test(org.junit.jupiter.api.Test) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) HandlerExceptionResolver(org.springframework.web.servlet.HandlerExceptionResolver) HandlerMapping(org.springframework.web.servlet.HandlerMapping) FixedThemeResolver(org.springframework.web.servlet.theme.FixedThemeResolver) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) FlashMapManager(org.springframework.web.servlet.FlashMapManager) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) ExceptionHandlerExceptionResolver(org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver) ConversionServiceExposingInterceptor(org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor) FLASH_MAP_MANAGER_BEAN_NAME(org.springframework.web.servlet.DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME) ResponseStatusExceptionResolver(org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) HandlerMethodReturnValueHandler(org.springframework.web.method.support.HandlerMethodReturnValueHandler) THEME_RESOLVER_BEAN_NAME(org.springframework.web.servlet.DispatcherServlet.THEME_RESOLVER_BEAN_NAME) REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME(org.springframework.web.servlet.DispatcherServlet.REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME) Ordered(org.springframework.core.Ordered) ResourceUrlProviderExposingInterceptor(org.springframework.web.servlet.resource.ResourceUrlProviderExposingInterceptor) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) ThemeResolver(org.springframework.web.servlet.ThemeResolver) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) JsonViewResponseBodyAdvice(org.springframework.web.servlet.mvc.method.annotation.JsonViewResponseBodyAdvice) InternalResourceViewResolver(org.springframework.web.servlet.view.InternalResourceViewResolver) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Controller(org.springframework.stereotype.Controller) Scope(org.springframework.context.annotation.Scope) RequestToViewNameTranslator(org.springframework.web.servlet.RequestToViewNameTranslator) LOCALE_RESOLVER_BEAN_NAME(org.springframework.web.servlet.DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME) CompositeUriComponentsContributor(org.springframework.web.method.support.CompositeUriComponentsContributor) HandlerInterceptor(org.springframework.web.servlet.HandlerInterceptor) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ConversionService(org.springframework.core.convert.ConversionService) MessageSource(org.springframework.context.MessageSource) ViewResolver(org.springframework.web.servlet.ViewResolver) PathMatcher(org.springframework.util.PathMatcher) ViewResolverComposite(org.springframework.web.servlet.view.ViewResolverComposite) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) FormattingConversionService(org.springframework.format.support.FormattingConversionService) ApplicationContext(org.springframework.context.ApplicationContext) BeanNameViewResolver(org.springframework.web.servlet.view.BeanNameViewResolver) HttpStatus(org.springframework.http.HttpStatus) BeanNameUrlHandlerMapping(org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping) UrlPathHelper(org.springframework.web.util.UrlPathHelper) Bean(org.springframework.context.annotation.Bean) DefaultHandlerExceptionResolver(org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver) MockServletContext(org.springframework.web.testfixture.servlet.MockServletContext) LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean) FormattingConversionService(org.springframework.format.support.FormattingConversionService) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ConfigurableWebBindingInitializer(org.springframework.web.bind.support.ConfigurableWebBindingInitializer) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) ConversionService(org.springframework.core.convert.ConversionService) FormattingConversionService(org.springframework.format.support.FormattingConversionService) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) List(java.util.List) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Validator(org.springframework.validation.Validator) Test(org.junit.jupiter.api.Test)

Example 4 with AbstractJackson2HttpMessageConverter

use of org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter in project spring-framework by spring-projects.

the class MvcNamespaceTests method testDefaultConfig.

@Test
public void testDefaultConfig() throws Exception {
    loadBeanDefinitions("mvc-config.xml");
    RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
    assertThat(mapping).isNotNull();
    assertThat(mapping.getOrder()).isEqualTo(0);
    assertThat(mapping.getUrlPathHelper().shouldRemoveSemicolonContent()).isTrue();
    mapping.setDefaultHandler(handlerMethod);
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.json");
    NativeWebRequest webRequest = new ServletWebRequest(request);
    ContentNegotiationManager manager = mapping.getContentNegotiationManager();
    assertThat(manager.resolveMediaTypes(webRequest)).as("Should not resolve file extensions by default").containsExactly(MediaType.ALL);
    RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
    assertThat(adapter).isNotNull();
    assertThat(new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect")).asInstanceOf(BOOLEAN).isFalse();
    List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
    assertThat(converters.size() > 0).isTrue();
    for (HttpMessageConverter<?> converter : converters) {
        if (converter instanceof AbstractJackson2HttpMessageConverter) {
            ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter) converter).getObjectMapper();
            assertThat(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse();
            assertThat(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION)).isFalse();
            assertThat(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)).isFalse();
            if (converter instanceof MappingJackson2XmlHttpMessageConverter) {
                assertThat(objectMapper.getClass()).isEqualTo(XmlMapper.class);
            }
        }
    }
    assertThat(appContext.getBean(FormattingConversionServiceFactoryBean.class)).isNotNull();
    assertThat(appContext.getBean(ConversionService.class)).isNotNull();
    assertThat(appContext.getBean(LocalValidatorFactoryBean.class)).isNotNull();
    assertThat(appContext.getBean(Validator.class)).isNotNull();
    assertThat(appContext.getBean("localeResolver", LocaleResolver.class)).isNotNull();
    assertThat(appContext.getBean("themeResolver", ThemeResolver.class)).isNotNull();
    assertThat(appContext.getBean("viewNameTranslator", RequestToViewNameTranslator.class)).isNotNull();
    assertThat(appContext.getBean("flashMapManager", FlashMapManager.class)).isNotNull();
    // default web binding initializer behavior test
    request = new MockHttpServletRequest("GET", "/");
    request.addParameter("date", "2009-10-31");
    request.addParameter("percent", "99.99%");
    MockHttpServletResponse response = new MockHttpServletResponse();
    HandlerExecutionChain chain = mapping.getHandler(request);
    assertThat(chain.getInterceptorList().size()).isEqualTo(1);
    assertThat(chain.getInterceptorList().get(0) instanceof ConversionServiceExposingInterceptor).isTrue();
    ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptorList().get(0);
    interceptor.preHandle(request, response, handlerMethod);
    assertThat(request.getAttribute(ConversionService.class.getName())).isSameAs(appContext.getBean(ConversionService.class));
    adapter.handle(request, response, handlerMethod);
    assertThat(handler.recordedValidationError).isTrue();
    assertThat(handler.date).isInSameDayAs("2009-10-31T00:00:00+00:00");
    assertThat(handler.percent).isEqualTo(Double.valueOf(0.9999));
    CompositeUriComponentsContributor uriComponentsContributor = this.appContext.getBean(MvcUriComponentsBuilder.MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME, CompositeUriComponentsContributor.class);
    assertThat(uriComponentsContributor).isNotNull();
    String name = "mvcHandlerMappingIntrospector";
    HandlerMappingIntrospector introspector = this.appContext.getBean(name, HandlerMappingIntrospector.class);
    assertThat(introspector).isNotNull();
    assertThat(introspector.getHandlerMappings().size()).isEqualTo(2);
    assertThat(introspector.getHandlerMappings().get(0)).isSameAs(mapping);
    assertThat(introspector.getHandlerMappings().get(1).getClass()).isEqualTo(BeanNameUrlHandlerMapping.class);
}
Also used : HandlerMappingIntrospector(org.springframework.web.servlet.handler.HandlerMappingIntrospector) MockHttpServletRequest(org.springframework.web.testfixture.servlet.MockHttpServletRequest) NativeWebRequest(org.springframework.web.context.request.NativeWebRequest) ContentNegotiationManager(org.springframework.web.accept.ContentNegotiationManager) CompositeUriComponentsContributor(org.springframework.web.method.support.CompositeUriComponentsContributor) HandlerExecutionChain(org.springframework.web.servlet.HandlerExecutionChain) ConversionServiceExposingInterceptor(org.springframework.web.servlet.handler.ConversionServiceExposingInterceptor) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) ConversionService(org.springframework.core.convert.ConversionService) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) AbstractJackson2HttpMessageConverter(org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter) RequestMappingHandlerMapping(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) RequestMappingHandlerAdapter(org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MockHttpServletResponse(org.springframework.web.testfixture.servlet.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Aggregations

HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)4 AbstractJackson2HttpMessageConverter (org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter)4 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)4 List (java.util.List)3 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)2 Locale (java.util.Locale)2 Optional (java.util.Optional)2 TimeUnit (java.util.concurrent.TimeUnit)2 Test (org.junit.jupiter.api.Test)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 Bean (org.springframework.context.annotation.Bean)2 Ordered (org.springframework.core.Ordered)2 ConversionService (org.springframework.core.convert.ConversionService)2 EnableSpringDataWebSupport (org.springframework.data.web.config.EnableSpringDataWebSupport)2 CacheControl (org.springframework.http.CacheControl)2 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)2 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)2 LocaleResolver (org.springframework.web.servlet.LocaleResolver)2