Example usage for org.springframework.web.accept ContentNegotiationManager ContentNegotiationManager

List of usage examples for org.springframework.web.accept ContentNegotiationManager ContentNegotiationManager

Introduction

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

Prototype

public ContentNegotiationManager(Collection<ContentNegotiationStrategy> strategies) 

Source Link

Document

A collection-based alternative to #ContentNegotiationManager(ContentNegotiationStrategy) .

Usage

From source file:org.elasticsoftware.elasticactors.examples.springweb.config.ApplicationContextConfiguration.java

@Bean
public ContentNegotiatingViewResolver contentNegotiatingViewResolver(ObjectMapper objectMapper) {
    ContentNegotiatingViewResolver viewResolver = new ContentNegotiatingViewResolver();
    viewResolver.setOrder(1);//from ww w. j a  v  a 2  s  . co m
    viewResolver.setUseNotAcceptableStatusCode(true);

    // set content negotiation manager
    Map<String, MediaType> mediaTypes = new HashMap<>();
    mediaTypes.put("json", MediaType.APPLICATION_JSON);
    PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(mediaTypes);
    ContentNegotiationManager manager = new ContentNegotiationManager(strategy);
    viewResolver.setContentNegotiationManager(manager);

    // set views
    List<View> views = new ArrayList<>();
    MappingJackson2JsonView view = new MappingJackson2JsonView();
    view.setExtractValueFromSingleKeyModel(true);
    view.setObjectMapper(objectMapper);
    views.add(view);
    viewResolver.setDefaultViews(views);

    return viewResolver;
}

From source file:org.fede.calculator.web.MvcConfig.java

@Bean
public ContentNegotiatingViewResolver cnResolver() {
    ContentNegotiatingViewResolver bean = new ContentNegotiatingViewResolver();
    bean.setOrder(0);//from w  w  w  . ja v  a  2  s  . c om
    bean.setContentNegotiationManager(new ContentNegotiationManager(new PathExtensionContentNegotiationStrategy(
            Collections.singletonMap("json", MediaType.APPLICATION_JSON))));

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

    bean.setDefaultViews(Arrays.asList(new View[] { jacksonView }));
    return bean;
}