Using these deps: feign-core and feign-gson 12.3. feign-form 3.8.0. JDK 19.
I can't get JSON serialisation working when using POST multipart/form-data for POJO->JSON and File.
Example:
interface Example {
static Example createInstance() {
return Feign.builder()
.encoder(new FormEncoder(new GsonEncoder()))
.target(Example.class, "https://anything.com");
}
@RequestLine("POST")
@Headers("Content-Type: multipart/form-data")
void uploadWithDto(@Param("dto") Dto dto, @Param("file") File file);
record Dto(String word, int number) {}
public static void main(String[] args) throws URISyntaxException {
Example api = Example.createInstance();
File file = new File(Thread.currentThread().getContextClassLoader().getResource("file.txt").toURI());
api.uploadWithDto(new Dto("hello", 123), file);
}
}
Debugger showed the POJO is not written to the output at all:

If I serialise the POJO first then it works, (but uses text/plain):
interface Example {
static Example createInstance() {
return Feign.builder()
.encoder(new FormEncoder(new GsonEncoder()))
.target(Example.class, "https://anything.com");
}
@RequestLine("POST")
@Headers("Content-Type: multipart/form-data")
void uploadWithDto(@Param("dto") String dto, @Param("file") File file);
record Dto(String word, int number) {}
public static void main(String[] args) throws URISyntaxException {
Example api = Example.createInstance();
File file =
new File(Thread.currentThread().getContextClassLoader().getResource("file.txt").toURI());
api.uploadWithDto(new Gson().toJson(new Dto("hello", 123)), file);
}
}

There have been previous issues (#24, #28) on this but I haven't been able to get it to work, what am I missing 😕? Also I'm not using Spring which many answers/solutions seem to use.
Using these deps:
feign-coreandfeign-gson12.3.feign-form3.8.0. JDK 19.I can't get JSON serialisation working when using
POST multipart/form-datafor POJO->JSON and File.Example:
Debugger showed the POJO is not written to the output at all:

If I serialise the POJO first then it works, (but uses
text/plain):There have been previous issues (#24, #28) on this but I haven't been able to get it to work, what am I missing 😕? Also I'm not using Spring which many answers/solutions seem to use.