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

Add support for more flexible header row(s) #32

Closed
lyonssp opened this issue Aug 23, 2017 · 3 comments
Closed

Add support for more flexible header row(s) #32

lyonssp opened this issue Aug 23, 2017 · 3 comments
Labels

Comments

@lyonssp
Copy link

lyonssp commented Aug 23, 2017

In enterprise contexts, CSV formats can take on really strange formats, and in my experience those formats commonly include sub-headers, headers that do not correspond to lower row values, and placeholders for CSVs that serve as templates to be filled in.

Jackson doesn't seem to currently support anything except the idea of a single header corresponding to the data that will be in a CSV.

There are libraries that do accomplish this -- I've used beanio -- but are just archaic in almost every other way. We use Jackson so much for other dataformats and use-cases, I'd love to keep to Jackson for CSVs as well.

@cowtowncoder
Copy link
Member

@lyonssp I am sure there are all kinds of esoteric "sub-formats" in use, as well as macro substitutions cases. For improvements, however, suggestions need to be bit more concrete.

There are some existing pieces of functionality that may be of use. One example is @JsonUnwrapped which allows flattening/unflattening to some degree. Specifically what is flat in CSV can be (more) structured at POJO level.

As to macro replacement I think this should be outside of core decoder, in form of pluggable handlers (with perhaps one or two standard implementations). One such idea is:

FasterXML/jackson-core#355

which in some form or other would allow handlers to "refine" (or perhaps transform) incoming String values. One use case would be macro expansion for simple value substitution.
More structured replacement (and imports) is something that can not be done at this level, and are probably strictly out of scope for Jackson,.

So, I guess I am open to improvement ideas. They just need to be somewhat specific wrt what to improve; but also generic in the sense that ideally concept is applicable to more than one backend format, in some form.

@lyonssp
Copy link
Author

lyonssp commented Aug 23, 2017

Sure, I'll go more specific than my original headline. In my particular use-case, I'm just trying to provide a CSV template that is meant to be filled in and returned in the same format. Clients have found it helpful to have placeholder values underneath the header to indicate what the significance of the column is.

Let me provide an example:

class CsvRow {
    @JsonProperty("first")
    private String firstName;

    @JsonProperty("last")
    private String lastName;

    @JsonProperty("dob")
    private LocalDate dateOfBirth;
}

If I want to write records of this type into a CSV, then I would next go ahead and create a CsvSchema, and in my case I'm going to use withHeader so that my CSV ultimately might look something like this with one record:

first,last,dob
reed,johnson,1993-12-13

Now, in my use-case, I want to have the ability to create a CSV like

first,last,dob
a first name, a last name, a date of birth

using the same source of truth for a header that I'm using to interpret the file when it comes back, or in other words the same CsvSchema.

I guess this amounts to being able to force-write rows into the CSV that don't adhere to the CsvSchema that was passed

@cowtowncoder
Copy link
Member

Not quite sure of the ask here (whether this is for reading or just writing; how would feature be exposed etc) so will close. May be re-filed with bit more detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants