no suitable HttpMessageConverter found for response type

前端 未结 10 1781
深忆病人
深忆病人 2020-11-30 02:33

Using spring, with this code :

List> messageConverters = restTemplate.getMessageConverters();
for(HttpMessageConverter ht         


        
10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 02:57

    If you can't change server media-type response, you can extend GsonHttpMessageConverter to process additional support types

    public class MyGsonHttpMessageConverter extends GsonHttpMessageConverter {
        public MyGsonHttpMessageConverter() {
            List types = Arrays.asList(
                    new MediaType("text", "html", DEFAULT_CHARSET),
                    new MediaType("application", "json", DEFAULT_CHARSET),
                    new MediaType("application", "*+json", DEFAULT_CHARSET)
            );
            super.setSupportedMediaTypes(types);
        }
    }
    

提交回复
热议问题