I want my application to work even when ContentType header is not passed. The request body in my case is always a JSON. But the below code always throws an exception
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
public class UserController {
@PostMapping(value = "/updateUser", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateUserDetails(@RequestBody User user) {
//Do something
}
This was expected, but even after creating a custom config, it gives the same error:
@Configuration
public class MyWebConfig implements WebMvcConfigurer {
@Override
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON);
}
}
This works fine if I pass the ContentType header which i want to make purely optional. Please help.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…