Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 5, 2025
2 parents 4c14f92 + 1f1cbbf commit e5d05b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ protected void _readHeaderLine() throws JacksonException {

while ((name = _reader.nextString()) != null) {
// one more thing: always trim names, regardless of config settings
// TODO!!! [dataformats-text#31]: Allow disabling of trimming
name = name.trim();
// See if "old" schema defined type; if so, use that type...
CsvSchema.Column prev = _schema.column(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ protected static class Entry {
/**********************************************************************
*/

private final CsvMapper MAPPER = mapperForCsv();

public void testSimpleHeader() throws Exception
{
CsvMapper mapper = mapperForCsv();
CsvParser parser = (CsvParser) mapper.reader(CsvSchema.emptySchema().withHeader())
CsvParser parser = (CsvParser) MAPPER.reader(CsvSchema.emptySchema().withHeader())
.createParser("name, age, other\nfoo,2,xyz\n");
// need to enable first-line-as-schema handling:
assertToken(JsonToken.START_OBJECT, parser.nextToken());
Expand All @@ -42,11 +43,8 @@ public void testSimpleHeader() throws Exception

public void testSimpleQuotes() throws Exception
{
CsvMapper mapper = mapperForCsv();
CsvSchema schema = CsvSchema.emptySchema().withHeader();
Entry entry = mapper.readerFor(Entry.class).with(schema)
.without(CsvReadFeature.WRAP_AS_ARRAY)
.readValue(
Entry entry = MAPPER.readerFor(Entry.class).with(schema).readValue(
"name,age,\"cute\" \nLeo,4,true\n");
assertEquals("Leo", entry.name);
assertEquals(4, entry.age);
Expand All @@ -55,11 +53,8 @@ public void testSimpleQuotes() throws Exception

public void testSkipFirstDataLine() throws Exception
{
CsvMapper mapper = mapperForCsv();
CsvSchema schema = mapper.schemaFor(Entry.class).withSkipFirstDataRow(true);
MappingIterator<Entry> it = mapper.readerFor(Entry.class).with(schema)
.without(CsvReadFeature.WRAP_AS_ARRAY)
.readValues(
CsvSchema schema = MAPPER.schemaFor(Entry.class).withSkipFirstDataRow(true);
MappingIterator<Entry> it = MAPPER.readerFor(Entry.class).with(schema).readValues(
"12354\n6,Lila,true");
Entry entry;

Expand Down Expand Up @@ -88,13 +83,10 @@ public void testLongHeader() throws Exception
final String CSV = sb.toString();


// Ok, then, first let's try reading columns:

CsvMapper mapper = mapperForCsv();
// Ok, then, first let's try reading columns:
CsvSchema schema = CsvSchema.emptySchema().withHeader();
CsvParser p = (CsvParser) mapper.reader()
CsvParser p = (CsvParser) MAPPER.reader()
.with(schema)
.without(CsvReadFeature.WRAP_AS_ARRAY)
.createParser(CSV);
// need to read something to ensure header line is processed
assertEquals(JsonToken.START_OBJECT, p.nextToken());
Expand All @@ -121,13 +113,10 @@ public void testLongColumnName() throws Exception
sb.append("\nabc\n");
final String CSV = sb.toString();

// Ok, then, first let's try reading columns:

CsvMapper mapper = mapperForCsv();
// Ok, then, first let's try reading columns:
CsvSchema schema = CsvSchema.emptySchema().withHeader();
CsvParser p = (CsvParser) mapper.reader()
CsvParser p = (CsvParser) MAPPER.reader()
.with(schema)
.without(CsvReadFeature.WRAP_AS_ARRAY)
.createParser(CSV);
// need to read something to ensure header line is processed
assertEquals(JsonToken.START_OBJECT, p.nextToken());
Expand All @@ -138,6 +127,12 @@ public void testLongColumnName() throws Exception
p.close();
}

// [dataformats-text#31]: Allow disabling header name trimming
public void testHeaderNamePadding() throws Exception
{
// TODO
}

/*
/**********************************************************************
/* Test methods, fail
Expand All @@ -146,13 +141,11 @@ public void testLongColumnName() throws Exception

public void testInvalidMissingHeader() throws Exception
{
CsvMapper mapper = mapperForCsv();
try {
mapper.readerFor(Entry.class).with(CsvSchema.emptySchema().withHeader()).readValue(" \nJoseph,57,false");
MAPPER.readerFor(Entry.class).with(CsvSchema.emptySchema().withHeader()).readValue(" \nJoseph,57,false");
fail("Should have failed with exception");
} catch (Exception e) {
verifyException(e, "Empty header line");
}
}

}

0 comments on commit e5d05b9

Please sign in to comment.