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

CsvParser.Feature.ALLOW_TRAILING_COMMA doesn't work with header columns #204

Closed
bjmi opened this issue Jul 2, 2020 · 4 comments
Closed
Milestone

Comments

@bjmi
Copy link

bjmi commented Jul 2, 2020

When reading given CSV with jackson-dataformat-csv 2.9.9

name,age,
Roger,27,
Chris,53,

using following lines

List<Person> persons = new CsvMapper()
    .enable(CsvParser.Feature.ALLOW_TRAILING_COMMA)
    .readerFor(Person.class)
    .with(CsvSchema.emptySchema().withHeader())
    .<Person> readValues(csvAsString)
    .readAll();
...
class Person {
    public String name;
    public int age;
}

results in

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "" (class Person), not marked as ignorable (2 known properties: "name", "age"])
 at [Source: (StringReader); line: 2, column: 10] (through reference chain: Person[""])
	at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:61)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnknownProperty(DeserializationContext.java:823)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1153)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownProperty(BeanDeserializerBase.java:1589)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handleUnknownVanilla(BeanDeserializerBase.java:1567)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:294)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:151)
	at com.fasterxml.jackson.databind.MappingIterator.nextValue(MappingIterator.java:277)
	at com.fasterxml.jackson.databind.MappingIterator.readAll(MappingIterator.java:317)
	at com.fasterxml.jackson.databind.MappingIterator.readAll(MappingIterator.java:303)

The single trailing comma should be allowed in header columns too and should not raise an exception.

@cowtowncoder
Copy link
Member

Sounds like a problem: thank you for reporting this.

@cowtowncoder cowtowncoder modified the milestones: 2.10, 2.11.2 Jul 11, 2020
@cowtowncoder cowtowncoder added 2.11 and removed 2.10 labels Jul 11, 2020
@cowtowncoder cowtowncoder changed the title CSV feature ALLOW_TRAILING_COMMA doesn't work with header columns CsvParser.Feature.ALLOW_TRAILING_COMMA doesn't work with header columns Jul 11, 2020
@bjmi
Copy link
Author

bjmi commented Jul 20, 2020

Are there any chances this can go to 2.10 too?

@cowtowncoder
Copy link
Member

Was about to say no, due to risk, but looking at changes sure I can backport this I think.

@cowtowncoder cowtowncoder removed this from the 2.11.2 milestone Jul 21, 2020
cowtowncoder added a commit that referenced this issue Jul 21, 2020
@cowtowncoder cowtowncoder added this to the 2.10.5 milestone Jul 21, 2020
@cowtowncoder
Copy link
Member

So, fixed for:

  • 2.10.5
  • 2.11.2

@cowtowncoder cowtowncoder added 2.10 and removed 2.11 labels Jul 21, 2020
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