-
Notifications
You must be signed in to change notification settings - Fork 22
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
Integer shouldn't be formatted by default on writing to CSV #83
Comments
Can you provide a sample app showing this? I don't recall ever seeing that situation myself and it doesn't make sense. |
public class CsveedTest {
public class Bean {
private Integer first;
private Long second;
public Bean(Integer first, Long second) {
this.first = first;
this.second = second;
}
public Integer getFirst() {
return first;
}
public void setFirst(Integer first) {
this.first = first;
}
public Long getSecond() {
return second;
}
public void setSecond(Long second) {
this.second = second;
}
}
@Test
public void bugReason(){
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
String value = numberFormat.format(6666);
assertEquals("6,666", value);
}
@Test
public void bugSolution(){
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
numberFormat.setGroupingUsed(false);
String value = numberFormat.format(6666);
assertEquals("6666", value);
}
@Test
public void testLocale() throws IOException {
List<Bean> beans = new ArrayList<>();
beans.add(new Bean(2222,6666L));
StringWriter writer = new StringWriter();
BeanWriter<Bean> beanWriter = new BeanWriterImpl<Bean>(writer, Bean.class);
beanWriter.writeBeans(beans);
writer.close();
System.out.print(writer.getBuffer().toString());
assertEquals("\"first\";\"second\"\r\n" +
"\"2222\";\"6666\"\r\n",
writer.getBuffer().toString());
}
} |
@subey I agree this is a issue in some use cases. However, not the easiest to fix in this library without a lot of changes. The reason behind that is that the library allows and is preferenced on locals outside the US. And a lot of those locals have their own settings. While it appears this library can handle this on reading, the writting portion seems to ignore overriding it. The fact though that it quotes it sort of tells me the output while not necessarily liked is proper. I'm going to leave this open as it is valid concern that eventually needs addressed. If you want to take a crack at trying to fix this library that would be great. Otherwise can you confirm if this ultimately is causing any real significant issue currently other than look and feel. |
Example:
Bean: Integer has value 6666
Generated CSV: "6,666"
The text was updated successfully, but these errors were encountered: