Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

FormData not work in version 3.4.0 #48

@chowc

Description

@chowc

code

  • dependency
<dependency>
        <groupId>io.github.openfeign.form</groupId>
        <artifactId>feign-form-spring</artifactId>
        <version>3.4.0</version>
</dependency>
  • server code
@FeignClient(value = "file-api")
public interface FileApi {
    @ResponseBody
    @PostMapping("/file/uploadformdata")
    String uploadFile(@RequestBody FormData data);
}
  • client code
  1. Application
@EnableEurekaClient
@EnableCircuitBreaker
@SpringBootApplication
@EnableTransactionManagement
@MapperScan("com.xxx.mapper")
@EnableSwagger2Doc
@EnableFeignClients
public class ClientApplication {
    public static void main(String[] args) {
        SpringApplication.run(ClientApplication.class, args);
    }

    @Configuration
    static class ClientConfiguration {
        @Bean
        public Encoder feignEncoder(ObjectFactory<HttpMessageConverters> messageConverters) {
            return new SpringFormEncoder(new SpringEncoder(messageConverters));
        }
    }
}
  1. the real code invoke server api
@Autowired
private FileApi fileApi;

@Test
public void print() throws Exception {
	Path path = Paths.get("src/test/resources/test.txt");
	String name = "file";
	String originalFileName = "src/test/resources/test.txt";
	String contentType = "application/octet-stream";
	byte[] content = Files.readAllBytes(path);
	// 3.4.0 not works
	//FormData formData = new FormData("application/octet-stream", "mockname.txt", content);
        // 3.3.0 works here
	FormData formData = new FormData("application/octet-stream", content);
	fileApi.uploadFile(formData);
}

error message

Caused by: feign.FeignException: status 500 reading FileApi#uploadFile(FormData); content:
{"timestamp":"2018-10-26 11:38:40","status":500,"error":"Internal Server Error","message":"Type definition error: [simple type, class feign.form.FormData]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `feign.form.FormData` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)\n at [Source: (PushbackInputStream); line: 1, column: 2]","path":"/file/uploadformdata"}
	at feign.FeignException.errorStatus(FeignException.java:62)
	at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:91)
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:138)
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76)
	at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:108)
	at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:302)
	at com.netflix.hystrix.HystrixCommand$2.call(HystrixCommand.java:298)
	at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46)
	... 27 more

Thanks for any help!

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions