1

I am trying to raise a feign client post request where I need to pass a JSON (multi-line text) and not a file. I am passing the content-type as multipart/form-data. And in my method, I am passing a POJO (containing all the fields that will be in the JSON) with @RequestPart annotation. And my builder has a SpringFormEncoder. But I am getting a 400 Bad Request in response. Can you please let me know what am I doing wrong here? Feign Client -

@RequestLine("POST /test")
@Headers({"Content-Type: multipart/form-data"})
void testmethod(@RequestPart(value="name") MyObject myobj);

Builder -

@Bean
public Encoder feignEncoder(){
 return new SpringFormEncoder(new SpringEncoder(this.messageConverters));
}

And I want the json to be sent in this format - { "firstField": "field value", "secondField": "second value }

the_novice
  • 105
  • 7

1 Answers1

0

I had similar problem when sending json type of payload as form-data content-type. My solution was to use JsonFormWriter. On your feign configuration class, add this:

@Bean
public JsonFormWriter jsonFormWriter() {
   return JsonFormWriter()
}

This might also help: Feign multipart with Json request part

kitessunny
  • 26
  • 3