Parsing arrays enclosed in square brackets

24 views
Skip to first unread message

Marek Andreánsky

unread,
Jun 14, 2020, 1:08:25 PM6/14/20
to jackson-user
Hi,
first time poster with a question that is probably easy to resolve, but the solution eluded me so far.

I'm trying to parse a .csv file with built in arrays (this file) following a Baeldung tutorial but the colons in arrays are confusing the parser, and I am unsure how to tell it what I am giving it.

Too many entries: expected at most 16 (value #16 (15 chars) """60 - Pipboy""")
 at [Source: (com.fasterxml.jackson.dataformat.csv.impl.UTF8Reader); line: 5, column: 188]

Jackson is a powerful library and I would like to learn to use it more for other data types (really nice for parsing Jsons) but am currently stuck at this issue.

Any ideas?

Tatu Saloranta

unread,
Jun 14, 2020, 1:39:38 PM6/14/20
to jackson-user
There is no support for this notation currently: array values are
expected to be included without extra surrounding, separated by
"arrayElementSeparator" which defaults to semicolon ";" (but
configurable using `CsvSchema`).

If someone wants to work on functionality to allow "wrapped" values
(it sounds like a reasonable idea to me), I can help, but until this
is implemented you would need to use a custom deserializer that reads
a String value (JsonToken.VALUE_STRING) and processes it as expected.

-+ Tatu +-

Marek Andreánsky

unread,
Jun 14, 2020, 3:01:45 PM6/14/20
to jackso...@googlegroups.com
Thanks for the reply, that is what I thought as well - getting it out as a string and parsing it, but was researching if it can be done in a more elegant way via the library. I could open an issue or enhancement request on GitHub for this if you think its worthwhile to keep track of.

Would be nice if we could specify enclosing tags for an array inside csvs without resorting to parsing strings as I did encounter similar notations (array elements in square brackets separated by colons) before.

And the tools I used to inspect the csv (Rons csv editor and VS code) all said the csv is valid.

--
You received this message because you are subscribed to the Google Groups "jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAL4a10gn3ZbFuMUK5tmJ7XpOyjv4DCuX4_mfNNtRVZxBFeZefQ%40mail.gmail.com.

Tatu Saloranta

unread,
Jun 14, 2020, 3:43:51 PM6/14/20
to jackson-user
On Sun, Jun 14, 2020 at 12:01 PM Marek Andreánsky <ma...@andreansky.sk> wrote:
>
> Thanks for the reply, that is what I thought as well - getting it out as a string and parsing it, but was researching if it can be done in a more elegant way via the library. I could open an issue or enhancement request on GitHub for this if you think its worthwhile to keep track of.
>
> Would be nice if we could specify enclosing tags for an array inside csvs without resorting to parsing strings as I did encounter similar notations (array elements in square brackets separated by colons) before.
>
> And the tools I used to inspect the csv (Rons csv editor and VS code) all said the csv is valid.

If decoding of CSV content fails, when attempting to bind to a String
property, that is probably worth filing an issue for,
as that is bit different question? I can't say for sure without
looking deeper but that could be a bug.

-+ Tatu +-
> To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CALP9Fj9v3uQEwPqKOWMsWnufsMv-wNbW3YJPFaHnefae%2B0H85w%40mail.gmail.com.

Tatu Saloranta

unread,
Jun 14, 2020, 3:47:15 PM6/14/20
to jackson-user
On Sun, Jun 14, 2020 at 12:43 PM Tatu Saloranta <ta...@fasterxml.com> wrote:
>
> On Sun, Jun 14, 2020 at 12:01 PM Marek Andreánsky <ma...@andreansky.sk> wrote:
> >
> > Thanks for the reply, that is what I thought as well - getting it out as a string and parsing it, but was researching if it can be done in a more elegant way via the library. I could open an issue or enhancement request on GitHub for this if you think its worthwhile to keep track of.
> >
> > Would be nice if we could specify enclosing tags for an array inside csvs without resorting to parsing strings as I did encounter similar notations (array elements in square brackets separated by colons) before.
> >
> > And the tools I used to inspect the csv (Rons csv editor and VS code) all said the csv is valid.
>
> If decoding of CSV content fails, when attempting to bind to a String
> property, that is probably worth filing an issue for,
> as that is bit different question? I can't say for sure without
> looking deeper but that could be a bug.

... also, forgot to ask one more thing: if you are aware of any
specification or guidance for "bracket arrays in CSV" notation, a link
would be nice to support need. There are many de-facto conventions as
there isn't really definitive CSV specification even just for basic
things, but many conventions supported by various tools. I would be
happy to add links from CSV module repo to various document usages,
even if just to point that specific one is not explicitly supported.
It would also be easier to figure out how likely some
features/notations are to be used by large number of people: sometimes
feature requests are just for usage within one company, for example,
and other times larger ecosystems use specific variation.
Knowing context helps evaluate things.

-+ Tatu +-

Marek Andreánsky

unread,
Jun 23, 2020, 12:42:10 AM6/23/20
to jackso...@googlegroups.com
Sorry for the late reply, I have been trying to find specification but nothing concrete for arrays yet. Purely from my experience however, I was working with .csvs that had arrays stored between square brackets such as [item1][item2][item3]. I did notice that sometimes flattened .json files follow this structure as well for arrays.

But maybe a generic implementation would work - allowing us to specify enclosing characters for array elements as well as an optional separator character. I know we can make our own parsers for these cases, but would be nice to have a way to do this via the existing framework.

But as you said, the specification is not there, and several parties use different data structures, especially when flattening out data in a csv.

Reply all
Reply to author
Forward
0 new messages