I am updating spring-boot from 1.3.6 to 2.1.3 and while before responses had content type application/json;charset=UTF-8
, now I am getting a charset of iso-8859-1.
I would like to have utf 8.
My controller looks like this:
@Controller
public class MyController {
@RequestMapping(value={"/myService/{serviceId}"}, method=RequestMethod.POST, consumes="application/json")
public ResponseEntity<Void> handlePostServiceId(final InputStream requestInputStream,
@PathVariable String serviceId,
final HttpServletRequest servletRequest,) {
<$businessLogic>
return new ResponseEntity<>(new HttpHeaders(), HttpStatus.ACCEPTED);
}
I can get it to return utf-8 if I include produces= MediaType.APPLICATION_JSON_UTF8_VALUE
in my @RequestMapping
but I would like to only have to set that once, rather than for every single API.
I also tried adding
@Override
public void configureContentNegotiation(
ContentNegotiationConfigurer configurer) {
configurer.defaultContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
}
to my WebMvcConfigurer as suggested here: https://stackoverflow.com/a/25275291/2855921 but that broke my availability api which consumes plain/text content type.
I also ensured that my request was UTF-8, so it is not just mirroring back the format I gave.
Any ideas on how I can set the charset to be UTF-8 for the entire project?