jackson-dataformats-text icon indicating copy to clipboard operation
jackson-dataformats-text copied to clipboard

Polymorphic CSV Reading and Writing

Open JKerwood opened this issue 6 years ago • 2 comments

Can the CSV mapper handle polymorphic reading and writing. If it can could you show a quick example?

JKerwood avatar Apr 24 '18 15:04 JKerwood

If you have concrete suggestion for additional functionality (or even a general idea), yes, feel free to add here. At this point polymorphic handling is not really supported.

If this is more of a question (or start of discussion), please use mailing list:

https://groups.google.com/group/jackson-user/

as issue tracker is not meant as discussion or support forum.

cowtowncoder avatar Apr 24 '18 16:04 cowtowncoder

I've hit this issue recently in work. I used your CsvSchema classes to speculatively detect polymorphic array members already... Then found that the csv itself wouldn't deserialize because the JsonParser attached to the CsvMapper has only a single CsvSchema attached. I can apply the same concepts I used for the validation here to inspect the JsonTypeInfo data and swap out the CsvSchema on the JsonParser based on the type field. It's a bit of an overhaul as there's a few ways to apply the polymorphic typing with Jackson but I'm going to have a crack at this and try get a PR in for you. Also, I may separately extend the column types to allow validating types a bit more accurate, ie. Distinguish between decimals and integers and potentially do a bit of date detection. Polymorphism first though. Are you guys open to PRs? I should be able to keep the performance impact as close to negligible as possible. It could be zero'd out if I make polymorphic handling a DeserializationFeature that has to be turned on by default.

stevenleadbeater avatar Aug 03 '18 17:08 stevenleadbeater