Sparsely populated POJO ( ignore columns ) #82
Comments
Note that Depending on how you construct But anyway, what you want is definitely doable, we just need to figure out what is the best way in your case. |
Thanks. So, if i understand this correctly, i need to define CsvSchema no matter what? No way to entirely do this via annotations on the POJO? To clarify- if i don't want to declare all columns in the CSV, as the POJO's fields ( via |
You can generate So: the question is, how could you add these placeholders. Currently the only way would be to manually build Now... perhaps there is a feature request here, which would actually add "virtual" properties for entries defined in But on short term, you could try first generating |
My use case is this: i have 100+ columns, and i'm interested in 3. I would prefer to be able to just say : "these are the 3 properties i'm interested in and this is their index. Ignore the rest". Preferably all via annotations :-) Seems to me there is no way to do this with annotations or by building a CsvSchema object. Is that correct? would you consider this too much of an edge-case? |
i should clarify: no way to do this without specifying all 100+ fields |
Right, there is no way to currently specify mapping for just a subset. But since you do know indexes, you could generate |
ok, thanks. I'll see if i can formulate a feature request around this maybe. |
I do not think this is an edge case. It seems to be pretty reasonable and I think this is the normal and most common use case. It probably does not get raised too much because in most cases people are just dropping out very few columns, so this ones can be easily handled with above technique, otherwise it is a real pain. If we consider that schema builder add columns by name setting a property to ignore CSB Columns not found on the POJO would be easy. |
@m-rossini I am not 100% sure what you asking here, so it might be best to actually file a new request with exact details. |
I currently have a use case where I'd like to extract two out of seventeen columns; the columns generally have a stable order but this is not something I'd want to rely on. (There is a header, so reordering shouldn't be a problem.) And in the future additional irrelevant columns may be introduced. So just to confirm: parsing a CSV file with an arbitrary number of extraneous columns with are arbitrarily sorted into a POJO which describes a subset of those columns is not currently supported? |
@Stephan202 Correct. Arbitrary extraction is not supported with name mapping. |
Hello-
i was wondering if this was an un-supported use case, ( and if you thought implementing it was feasible/sensible? ) or a bug?
annotation on the POJO
Parsing a CSV record of
Yields a type cast exception, because the value from the first column is being populated in to "theOne"
is @JsonPropertyOrder ignored? i tried annotating the field
which looked redundant and made no difference.
n.b.: If i add four fields of compatible types ( String, Integer, String, String ) all is fine. I can even shuffle them around in @JsonPropertyOrder and see the field values affected.
The text was updated successfully, but these errors were encountered: