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

Integer shouldn't be formatted by default on writing to CSV #83

Open
subey opened this issue Apr 12, 2017 · 3 comments
Open

Integer shouldn't be formatted by default on writing to CSV #83

subey opened this issue Apr 12, 2017 · 3 comments

Comments

@subey
Copy link

subey commented Apr 12, 2017

Example:
Bean: Integer has value 6666
Generated CSV: "6,666"

@hazendaz
Copy link
Collaborator

Can you provide a sample app showing this? I don't recall ever seeing that situation myself and it doesn't make sense.

@subey
Copy link
Author

subey commented Apr 25, 2017

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());

    }
}

@hazendaz
Copy link
Collaborator

hazendaz commented May 8, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants