Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring set default Content-type to "application/json;charset=utf-8" when Jackson is not used

I would like to change my spring app default "Content-type" to "application/json;charset=utf-8" instead of only "application/json"

like image 625
raonirenosto Avatar asked Jan 30 '26 08:01

raonirenosto


2 Answers

Spring > 4.3.4

@RequestMapping(produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
like image 67
R.A Avatar answered Feb 02 '26 02:02

R.A


@Configuration
@EnableWebMvc
public class MVCConfig extends WebMvcConfigurerAdapter {

    @Override
    public void configureContentNegotiation(
         ContentNegotiationConfigurer configurer) {
        final Map<String, String> parameterMap = new HashMap<String, String>();
        parameterMap.put("charset", "utf-8");

        configurer.defaultContentType(new MediaType(
          MediaType.APPLICATION_JSON, parameterMap));
    }
}
like image 25
raonirenosto Avatar answered Feb 02 '26 01:02

raonirenosto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!