Example usage for org.springframework.web.accept ContentNegotiationManagerFactoryBean addMediaType

List of usage examples for org.springframework.web.accept ContentNegotiationManagerFactoryBean addMediaType

Introduction

In this page you can find the example usage for org.springframework.web.accept ContentNegotiationManagerFactoryBean addMediaType.

Prototype

public void addMediaType(String fileExtension, MediaType mediaType) 

Source Link

Document

An alternative to #setMediaTypes for use in Java code.

Usage

From source file:org.shaigor.rest.retro.client.config.ClientWebMvcConfigurerAdapter.java

@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setDefaultViews(Arrays.<View>asList(new MappingJackson2JsonView()));
    return contentViewResolver;
}

From source file:com.mycompany.geocoordinate.config.AppConfiguration.java

@Bean
public ContentNegotiatingViewResolver contentViewResolver() {
    ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);

    MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
    defaultView.setExtractValueFromSingleKeyModel(true);

    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setViewResolvers(Arrays.<ViewResolver>asList(viewResolver()));
    contentViewResolver.setDefaultViews(Arrays.<View>asList(defaultView));
    return contentViewResolver;
}

From source file:org.shaigor.rest.retro.security.gateway.config.OAuth2WebMvcConfigurerAdapter.java

@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
    ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
    contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);

    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/jsp/");
    viewResolver.setSuffix(".jsp");

    MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
    defaultView.setExtractValueFromSingleKeyModel(true);

    ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
    contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
    contentViewResolver.setViewResolvers(Arrays.<ViewResolver>asList(viewResolver));
    contentViewResolver.setDefaultViews(Arrays.<View>asList(defaultView));
    return contentViewResolver;
}