resttemplate getForObject map responsetype

后端 未结 6 1754
囚心锁ツ
囚心锁ツ 2021-02-06 23:58

Update 02/05/2018 (about 4 years later)...I tested this again as people have been upvoting my question/answer and Sotirios Delimanolis is correct that I should not h

6条回答
  •  春和景丽
    2021-02-07 00:36

    I know its old, but just for other people that may visit this topic: If you want to register some additional converters with RestTemplateBuilder you also have to explicitly register default ones

    @Bean
    public RestTemplateBuilder builder() {
        return new RestTemplateBuilder()
                .defaultMessageConverters()
                .additionalMessageConverters(halMessageConverter());
    }
    
    private HttpMessageConverter halMessageConverter() {
        ObjectMapper objectMapper = new ObjectMapper().registerModule(new Jackson2HalModule());
        TypeConstrainedMappingJackson2HttpMessageConverter halConverter = new TypeConstrainedMappingJackson2HttpMessageConverter(ResourceSupport.class);
        halConverter.setSupportedMediaTypes(Collections.singletonList(MediaTypes.HAL_JSON));
        halConverter.setObjectMapper(objectMapper);
        return halConverter;
    }
    

提交回复
热议问题