Question

i am trying to write a jersey service which consumes a CSV file. i want to serialize that csv file into an object. what can i do to achieve this? i am going to use opencsv as the parser library for csv file.

my base structure of the service:

@POST
@Consumes(MediaType.TEXT_PLAIN){
        public void addUsers(@FormDataParam("file") InputStream inputStream) throws UnsupportedEncodingException{

    }

is the @Consumes annotation which i am using the right way as well?

Was it helpful?

Solution

This answer tells you how to convert CSV to an object in java - Java API to make an object from a CSV file

Are you uploading the CSV as a file ? Can you use a multipart upload instead (if that makes sense. Multipart let's you consider the file upload as an attachment of sorts. Usually there is meta-data associated with such requests, which can be sent as a separate part) ? CSV has it's own mime type as defined by RFC4180 although I'm unaware if jersey distinguishes it. As long as you read the stream using the right encoding you should be good.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top