[
https://issues.apache.org/jira/browse/GROOVY-12295?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-12295:
-------------------------------
Description:
The javadoc for {{CsvSlurper#parse(Reader)}} states:
{quote}When {{useHeader}} is false, maps are keyed by auto-generated column
names.{quote}
No such auto-generation exists. With {{useHeader=false}}, any non-empty input
fails:
{code:groovy}
new groovy.csv.CsvSlurper().setUseHeader(false).parseText('1,2\n3,4')
{code}
throws:
{noformat}
groovy.csv.CsvRuntimeException
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException:
Cannot construct instance of `java.util.LinkedHashMap` (although at least one
Creator exists):
no String-argument constructor/factory method to deserialize from String value
('1')
{noformat}
*Cause:* {{buildSchema()}} with {{useHeader=false}} produces an empty
{{CsvSchema}} with no columns. jackson-dataformat-csv then presents each row as
an array of strings rather than an object, which cannot bind to {{Map}}, so the
entire untyped {{useHeader=false}} path is broken, not just an edge case.
*Possible resolutions:*
# Implement the documented behavior: peek at the first row to determine the
column count and generate names (e.g. {{column1}}..{{columnN}}), building the
schema from those.
# Return a list of string lists (one per row) when {{useHeader}} is false, and
adjust the docs accordingly.
# Keep current behavior but fix the javadoc and fail fast with a clear error
message.
Since the module is still {{@Incubating}}, any of these can be adopted without
compatibility concerns.
> CsvSlurper: parsing fails with useHeader=false despite documented
> auto-generated column names
> ---------------------------------------------------------------------------------------------
>
> Key: GROOVY-12295
> URL: https://issues.apache.org/jira/browse/GROOVY-12295
> Project: Groovy
> Issue Type: Bug
> Reporter: Paul King
> Priority: Major
>
> The javadoc for {{CsvSlurper#parse(Reader)}} states:
> {quote}When {{useHeader}} is false, maps are keyed by auto-generated column
> names.{quote}
> No such auto-generation exists. With {{useHeader=false}}, any non-empty input
> fails:
> {code:groovy}
> new groovy.csv.CsvSlurper().setUseHeader(false).parseText('1,2\n3,4')
> {code}
> throws:
> {noformat}
> groovy.csv.CsvRuntimeException
> Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException:
> Cannot construct instance of `java.util.LinkedHashMap` (although at least one
> Creator exists):
> no String-argument constructor/factory method to deserialize from String
> value ('1')
> {noformat}
> *Cause:* {{buildSchema()}} with {{useHeader=false}} produces an empty
> {{CsvSchema}} with no columns. jackson-dataformat-csv then presents each row
> as an array of strings rather than an object, which cannot bind to {{Map}},
> so the entire untyped {{useHeader=false}} path is broken, not just an edge
> case.
> *Possible resolutions:*
> # Implement the documented behavior: peek at the first row to determine the
> column count and generate names (e.g. {{column1}}..{{columnN}}), building the
> schema from those.
> # Return a list of string lists (one per row) when {{useHeader}} is false,
> and adjust the docs accordingly.
> # Keep current behavior but fix the javadoc and fail fast with a clear error
> message.
> Since the module is still {{@Incubating}}, any of these can be adopted
> without compatibility concerns.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)