-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Serializer] csv_headers
not working as expected
#55048
Comments
Just found the PR that introduced the I may open a PR to change that behaviour with something like this: If the key of the array passed to $contextBuilder = (new CsvEncoderContextBuilder())->withHeaders([
'Prénom' => 'firstName',
'Nom' => 'lastName',
'Nested field label' => 'nested.field',
]); We should be able to keep BC like this. What do you think? |
I think your example would work fine if you added class YourEntity
{
#[SerializedName('Prénom')]
public string $firstName;
#[SerializedName('Nom')]
public string $lastName;
} Of course it may be a design decision to not want to do that, especially until #53858 is implemented. Anyway, I don't see any bug here, in your serializer context you've defined
1 & 2 do not know anything about each other, no mapping is supposed to be happening apart from name converter. |
I did not know about the However, since i want to set the label only when serializing into CSV, I do not want to use attributes on entities (looks like I cannot specify that the names should be used only for CSV). |
Symfony version(s) affected
7.0.7
Description
The
CsvEncoder
has an option to specify the CSV headers, but it doesn't look to work as expected.When specifying header, the CSV is generated with new columns added.
How to reproduce
Result:
Expected result:
Possible Solution
Probably something wrong here:
symfony/src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
Line 89 in 4bf657a
Additional Context
No response
The text was updated successfully, but these errors were encountered: