-
Notifications
You must be signed in to change notification settings - Fork 82
POST JSON with File not working (multipart/form-data) #118
Comments
Btw the |
Facing the same issue. Basically, sending an object in the |
First of all the PojoWriter ignores final and static fields, and in Java record all fields are final. Use Java class instead. The second part of the issue is that the PojoWriter writes all fields of a pojo as a part of a multipart/form-data request. You may follow this solution to solve the problem. |
I had the same issue and I resolved it like below. I'm using jackson here but it doesn't matter as long as you are able to serialize your dto to json string: var json = mapper.writeValueAsString(data);
this.data = FormData.builder().fileName("dto").data(json.getBytes()).contentType("application/json").build(); And my client method looks as follows: @RequestLine("POST /myEndpoint")
@Headers("Content-Type: multipart/form-data")
ResponseData<Void> myMethod(
@Param("dto") FormData dto,
@Param("files") List<File> files
); |
Using these deps:
feign-core
andfeign-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:
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.
The text was updated successfully, but these errors were encountered: