Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add an option to CsvEncoder to omit the header #27447
@tamasd , I think I'm not understanding: you send the CSV file as is or you send the CSV data after having processed the CSV file?
In the first case you should operate on the "other-app" side; if you send data contained in the CSV file, instead, you should remove the header before sending such data.
What is stopping you from removing the first line before processing the data in the CSV (either on your "client" side or on your "other-app" side): I'm missing this point...
To simplify the problem, I send the CSV content in the request body. Ideally, this encoder could encode my simple 2D array into CSV, and I can just send it as is. The "other app" is an external web API, I have no control over that. Basically, I store data in CSV format, and retrieve it (to display to the user), but the data might be changed by the "other app", and they don't need headers, since the format of the CSV is simple.
I can remove the first line of the resulting CSV, and add it back when I receive data, but it is a hacky solution. It would be much simplier if I could do something like
Currently I copied relevant parts from this class, but since we use a lot of Symfony components, it would be better if I could reuse this.
Ok, understood the problem.
Anyway, I think this is not a hacky way: you simply have to process the data for two different purposes:
I think this is not a useful option to be included in the symfony component.
I understand your point, but I think this is not a Serializer's purpose to manipulate data this way: it is your responsibility and you should use the Serializer component as is and then modify data to be sent to the API.
I don't understand why, to only strip out the header, you are copying the class just for this small feature.
In my opinion is much more correct to
And, more, there is another thing I don't understand: in the database, you save the headers (at least I understand you do from your words): so this means that also if you will remove them with the Serializer, you anyway need to have them somewhere in your code...
It is the other way around. I already have my 2D string array, I convert it to CSV, so I get numbers as headers, basically an extra line of data at the beginning of the string I get from the serializer. I need to remove that line, and add it back when I try to read the data, to be able to use this serializer.
A simple illustration: let's say I have a very simple piece data:
This happens the other way around as well. Let's say the "other app" has a piece of data with just
The problem here is that without manipulating the CSV string itself (which is something I am very uneasy to do, since it is the job of the encoder), I cause either data corruption or data loss.