an encoder support muliple pojos and multipleFile Array
See original GitHub issuewhen I refactor a project running on prouduct environment, I have to reserve some structual like it used to be. When I use feign, I found it not supported multiple Pojos likes below
// a consumer Feign Client example
@FeignClient(name= "spring-cloud-producer")
public interface HelloRemote3 {
@RequestLine(value = "POST /hello3")
public String hello3(
@Param(value = "name") String name,
@Param(value = "date") Date date,
@Param(value = "pojoA") PojoA pojoA,
@Param(value = "pojoBs") List<PojoB> pojoBs,
@Param(value = "pojoCMap") Map<String, PojoC> pojoCMap,
@Param(value = "file") MultipartFile file,
@Param(value = "files") MultipartFile[] files
);
}
but thanks Mr.pcan, I finally found A way to support this feature by rewrite Encoder with feignContact;
@see https://github.com/pcan/feign-client-test/blob/master/src/main/java/it/pcan/test/feign/client/FeignSpringFormEncoder.java
then , you can accept request in Producer SpringMvc Controller with @RequestPart ,like below
// producer Controller
@RestController
public class HelloController {
@RequestMapping(value = "/hello3")
public String index3(
@RequestPart(value = "name", required = false) String name,
@RequestPart(value = "date", required = false) Date date,
@RequestPart(value = "pojoA", required = false) PojoA pojoA,
@RequestPart(value = "pojoBs", required = false) List<pojoB> pojoBs,
@RequestPart(value = "pojoCMap", required = false) Map<String, pojoC> pojoCMap,
@RequestPart(value = "file", required = false) MultipartFile file,
@RequestPart(value = "files", required = false) MultipartFile[] files
) {
String result = "hello3 producer enter success \n";
result += " name: " + name;
result += " \n ------------ " + date;
result += " \n ------------" + JSONObject.toJSONString(pojoA);
result += " \n ------------ " + pojoBs;
result += " \n ------------ " + pojoCMap;
return result;
}
}
now, it works fine in my project. a complete demo @see https://github.com/jianguyuxing/feign-multiple-pojos could you support this feature in next version ?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Upload Multiple Files in Spring Boot using JPA, Thymeleaf ...
Open Mysql command line. Run create database filedb; and hit enter. FileModal.java. Let's write a simple POJO class that will serve as input...
Read more >Struts Multiple Files Upload Example - CodeJava.net
How to implement functionality to upload multiple files with ... In this POJO action class, we use three arrays to store uploaded files: ......
Read more >Binding external configurations to POJO classes - CalliCoder
External configurations allow you to work with the same code in different environments. In this article, we'll learn how to define and use ......
Read more >Howto upload multiple files with Spring Boot and test it with ...
I solved it using an Array instead of a Set with nested files. Java: @RequestMapping(value = "/upload", method = RequestMethod.
Read more >POJO Customization — Java Sync - MongoDB
In our guide on POJOs, we show how to specify a PojoCodecProvider which contains ... to serialize multiple POJO classes to documents in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

In fact , I rewrite nothing when Mr.Pcan’s encoder is complete now likes below
hm, I didn’t get what do you mean exactly.
To enable support for many body objects in a single method call - you need to rewrite feign.Contract, not the feign.Encoder, otherwise you will get “IllegalStateException: Method has too many Body parameters”. feign.Contract is responsible for parsing your client’s interface.
If you would like to have a support of
MultipartFile,MultipartFile[]and evenList<MultipartFile>- you need to take a look at this, I already have it (btw, thanks for the reminder, I just fixed a little bug there)