I'm trying to create a Post function in my REST API with the @FormDataParam annotation. However, when I try to test it with Postman the String that gets returned is very strange.
This is my method:
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createBrand(@FormDataParam("name") String name){
brandDAO.create(new Brand(name));
return Response
.ok("Name of brand = " + name)
.build();
}
Say I have the settings key = name
and value="test"
. I would expect that name
would be set to test, but it is actually set to:
----------------------------371301867522909150048733\r\nContent-Disposition: form-data; name=\"name\"; filename=\"\"\r\n\r\n\r\n----------------------------371301867522909150048733--\r\n
Have I misunderstood how to actually get the value from the form data, or am I using the method wrong?
If you are using Jersey 2, make sure you have registered the MultiPartFeature. If you don't the @FormDataParam
annotation will be ignored and it will be treated like the String is the entire entity, which is what looks like it going on.