spring-cloud/spring-cloud-openfeign

How to send data of type MultiValueMap via feign?

DJX-A opened this issue · 1 comments

DJX-A commented
        RestTemplate restTemplate = new RestTemplate();

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.MULTIPART_FORM_DATA);

        MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
        map.add("name", "test");
        map.add("name", "test2");
        map.add("age", "1");
        map.add("age", "2");
        map.add("age", "3");

        HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(map, headers);

        String url = "http://localhost:8081/form";
        String response = restTemplate.postForObject(url, requestEntity, String.class);

How can I get the above with feign?
I have tried defining the client as

@PostMapping(value = "/form",consumes = "multipart/form-data")
    String form(URI uri,@RequestPart MultiValueMap<String,Object> map);

Also I configured the encoder

    @Autowired
    private ObjectFactory<HttpMessageConverters> messageConverters;

    @Bean
    public Encoder feignFormEncoder () {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }

But it doesn't work as well, and doesn't end up sending the data out as RestTemplate does

DJX-A commented

I think I've figured out how to transmit this data type.
#539