FasterXML / jackson-dataformats-text

Uber-project for (some) standard Jackson textual format backends: csv, properties, yaml (xml to be added in future)
Apache License 2.0
406 stars 149 forks source link

Polymorphic CSV Reading and Writing #80

Open JKerwood opened 6 years ago

JKerwood commented 6 years ago

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

cowtowncoder commented 6 years ago

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.

stevenleadbeater commented 6 years ago

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.