uniVocity / univocity-parsers

uniVocity-parsers is a suite of extremely fast and reliable parsers for Java. It provides a consistent interface for handling different file formats, and a solid framework for the development of new parsers.
917 stars 252 forks source link

bug in setTypeOfColumns? #462

Closed cheenu2 closed 3 years ago

cheenu2 commented 3 years ago

Looks like a bug. Test fails with: expected: but was:

    @Test
    public void testSetTypeOfColumns() throws IOException {
        String data = "ID,NAME" + System.lineSeparator() + "2,Chris";
        InputStream csvStream = new ByteArrayInputStream(data.getBytes());
        CsvParser parser = new CsvParser(new CsvParserSettings() {
            {
                setHeaderExtractionEnabled(true);
            }
        });
        parser.beginParsing(csvStream);

        parser.getRecordMetadata().setTypeOfColumns(Integer.class, "ID");
        parser.getRecordMetadata().setTypeOfColumns(String.class, "NAME");

        Record record = parser.parseNextRecord();
        Map<String, Object> map = record.toFieldObjectMap();
        assertEquals(Integer.class, map.get("ID").getClass());
    }
cheenu2 commented 3 years ago

Got answer from https://stackoverflow.com/questions/67403644/univocity-csv-parser-settypeofcolumns-not-working Conversions are the ones that do the job: parser.getRecordMetadata().convertFields(new IntegerConversion()).add("ID");