This repository was archived by the owner on Dec 31, 2024. It is now read-only.
Description 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.
Reactions are currently unavailable
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.