Example usage for org.springframework.web.servlet.config.annotation ContentNegotiationConfigurer defaultContentTypeStrategy

List of usage examples for org.springframework.web.servlet.config.annotation ContentNegotiationConfigurer defaultContentTypeStrategy

Introduction

In this page you can find the example usage for org.springframework.web.servlet.config.annotation ContentNegotiationConfigurer defaultContentTypeStrategy.

Prototype

public ContentNegotiationConfigurer defaultContentTypeStrategy(ContentNegotiationStrategy defaultStrategy) 

Source Link

Document

Set a custom ContentNegotiationStrategy to use to determine the content type to use when no content type is requested.

Usage

From source file:io.spring.initializr.web.autoconfigure.InitializrWebConfig.java

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    configurer.defaultContentTypeStrategy(new CommandLineContentNegotiationStrategy());
}

From source file:xyz.lxie.springboot.api.SwaggerAutoConfiguration.java

@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
    configurer.favorPathExtension(true).ignoreUnknownPathExtensions(true).favorParameter(false)
            .ignoreAcceptHeader(true).useJaf(false).defaultContentType(MediaType.APPLICATION_JSON);

    // this is the key to make spring mvc respond with json result only!
    configurer.defaultContentTypeStrategy(nativeWebRequest -> {
        List<MediaType> medias = new ArrayList<>();
        medias.add(MediaType.APPLICATION_JSON);
        return medias;
    });/*from   w w w . j  av  a2  s  .  c  o m*/
}