相关文章推荐
淡定的盒饭  ·  Java reflection and ...·  4 天前    · 
单身的麦片  ·  Isle of Man TT Races© ...·  9 月前    · 
无邪的柑橘  ·  MySQL ...·  1 年前    · 
瘦瘦的小摩托  ·  javax.validation.Unexp ...·  1 年前    · 

Default content type in ContentNegotiationConfigurer not taken into account #29300

Closed as not planned
@membersound

Description

I have a @GetMapping @RestController that could produce both xml and json.
If Content-Type is missing in the clients' request, by default json should be returned.

I therefor tried to set ContentNegotiationConfigurer , but without any effect:

.w.s.m.s.DefaultHandlerExceptionResolver :
Resolved [org.springframework.http.converter.HttpMessageNotWritableException:
No converter for [class java.util.ImmutableCollections$Set12] with preset Content-Type 'null']

@Configuration
public class WebConfig implements WebMvcConfigurer {
	@Override
	public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
		configurer.defaultContentType(MediaType.APPLICATION_JSON);
@RestController
public class ExampleServlet {
	@GetMapping(value = "/test", produces = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
	public Set<String> test() {
		return Set.of("test");

When I change the code to produces=APPLICATION_JSON_VALUE only, everything works as expected. So the servlet in general should be fine.

spring-boot-2.7.4