Skip to content
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

Inconsistent default encoding in FlatFileItemReader and FlatFileItemWriter #1154

Closed
spring-projects-issues opened this issue Oct 27, 2015 · 1 comment

Comments

@spring-projects-issues
Copy link
Collaborator

Ant Kutschera opened BATCH-2448 and commented

We have a batch component which writes to an interjob file and another which reads from that file. They write and read using FlatFileItemWriter and FlatFileItemReader respectively.

Unfortunately the data which is read is no longer correct (our umlaut characters are corrupt), but the data in the interjob file is correct. This happens because the default encoding for FlatFileItemReader is not the same as the default encoding for FlatFileItemWriter. Looking at the source, they are:

org.springframework.batch.item.file.FlatFileItemReader#encoding = #DEFAULT_CHARSET = Charset.defaultCharset().name()

org.springframework.batch.item.file.FlatFileItemWriter#encoding = #OutputState.DEFAULT_CHARSET = "UTF-8"

I.e. the writer is hard coded to UTF-8 but the reader is environment specific.

Ideally the reader and the writer would use the same default regardless of the environment.

The work around is to set the encoding specifically to UTF-8 on the reader.

Affects:
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-infrastructure</artifactId>
<version>3.0.4.RELEASE</version>


Affects: 3.0.4

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 8, 2018

Mahmoud Ben Hassine commented

The fact that the FlatFileItemReader and FlatFileItemWriter don't have the same default encoding is not an issue as such, since both of them provide a way to specify the encoding for reading or writing. Now, I agree with you that ideally the FlatFileItemWriter should have Charset.defaultCharset().name() as default encoding to be consistent with the FlatFileItemReader, but this would be a breaking change.

@fmbenhassine fmbenhassine added this to the 5.0.0 milestone May 6, 2021
@fmbenhassine fmbenhassine removed the status: waiting-for-triage Issues that we did not analyse yet label May 6, 2021
cppwfs pushed a commit to cppwfs/spring-batch that referenced this issue May 17, 2021
resolves spring-projects#1154

It now matches the encoding scheme of FlatFileItemReader
cppwfs pushed a commit to cppwfs/spring-batch that referenced this issue May 17, 2021
resolves spring-projects#1154

It now matches the encoding scheme of FlatFileItemReader
cppwfs pushed a commit to cppwfs/spring-batch that referenced this issue May 17, 2021
resolves spring-projects#1154

It now matches the encoding scheme of FlatFileItemReader
@fmbenhassine fmbenhassine modified the milestones: 5.0.0, 5.0.0-M1 Sep 3, 2021
cppwfs pushed a commit to cppwfs/spring-batch that referenced this issue Sep 3, 2021
resolves spring-projects#1154

It now matches the encoding scheme of FlatFileItemReader
fmbenhassine added a commit that referenced this issue May 17, 2022
This commit overrides the fix in #3910 by using UTF-8
as default encoding in file-based item readers and writers.

Issue #1154
@fmbenhassine fmbenhassine changed the title FlatFileItemReader and FlatFileItemWriter don't have the same default encoding [BATCH-2448] Inconsistent default encoding in FlatFileItemReader and FlatFileItemWriter May 17, 2022
@fmbenhassine fmbenhassine modified the milestones: 5.0.0-M1, 5.0.0-M3 May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants