I am trying to write a method that will respond to this http request. Unfortunately, I do not know what the argument of such a method should be.
At first I thought it would be a Multipartfile and then I would just process it (see dummy approach below), but then I saw a "string" in swagger and it confused me a bit. I have no clue anymore what the format of the input data is.
(I know- I should use nio, no io)
I'm confused. You appear to be attempting to POST a CSV file named "data.csv". You post a file labelled "swagger", which is a YAML file (not CSV). Probably there's a MIME (Content-Type) more appropriate to use than "text/plain" for CSV. Like, say, "text/csv". But that's secondary.
Youd server-side code appears to expect MIME-multipart input, but your curl command is set up to simply blast raw data to the server without form variable naming, MIME or multi-partitioning. And that's OK, as long as the server doesn't try and treat it like is is any of those creatures. You want to configure to receive an InputStream, String, or similar character sequence without the extra stuff that an HTTP FORM submit would add.
I'm going to be a "small government" candidate. I'll be the government. Just me. No one else.
Multipart is a bad choice for CSVs. It's meant to send multiple values like a regular form post, but with files as well. MultipartFile is used for one element of a multipart request. You're not sending a multipart request so that's not going to work.
Your specifation says that the content type is "text/plain", and the type of the body parameter is "string". That means that you should just use String as body type, and parse the content yourself. A better option would be to use "text/csv", but I'm not sure how this can be easily mapped to objects.
Tim Holloway wrote:Plus, pretty much any textfile parser can parse strings by using a String Reader.
That statement is so important I'm quoting it. Every String can be turned into a Reader by using StringReader. Every byte can be turned into an InputStream by using ByteArrayInputStream. That allows you to use String and byte with code that can handle any type of text or binary input.
Besides that, Jackson's ObjectMapper has readValue methods that take a String. Combined with the data format I linked to you can have Jackson convert the CSV string into POJOs for you.