Java Spring resttemplate character encoding

后端 未结 5 503
甜味超标
甜味超标 2020-12-05 10:29

I\'m using the Java Spring Resttemplate for getting a json via a get request. The JSON I\'m getting has instead of special character slike ü ö ä or ß some weird stuff. So I

5条回答
  •  误落风尘
    2020-12-05 11:02

    You just need to add the StringHttpMessageConverter to the template's message converters:

    RestTemplate template = new RestTemplate();
    template.getMessageConverters()
            .add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));
    ResponseEntity response = template.exchange(endpoint, method, entity, 
                                                        Object.class);
    
        

    提交回复
    热议问题