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

(csv) Allow specifying custom String placeholder to use when a POJO would serialize as Object #13

Open
cowtowncoder opened this issue Mar 20, 2017 · 3 comments
Labels

Comments

@cowtowncoder
Copy link
Member

(from FasterXML/jackson-dataformat-csv#85 by @MattFriedmanAfilias)

When an object is encountered when writing CSV, the library throws an exception.

Problem: The model might be changed and an object field could be introduced. In this case, the developer will not necessarily update any tests to include the new field.

If that happens the error may only be detected at runtime. We want to detect such problems sooner, or avoid them altogether.

It should be possible to detect the error sooner, or to introduce a setting that would cause the exception to not be thrown and to provide instead some default behavior.

Such behavior might be to simply print "Object" or "n/a" when an object is encountered, rather than throwing an exception; a log message warning about this might be useful too.

The developer should be in control of this setting IMO. The library should make it possible for the developer to decide on the behavior rather than only throwing an exception for this scenario.

@cowtowncoder
Copy link
Member Author

On possible implementation: due to the way databinding/streaming API separation works, it is not (at least currently) possible to figure out potential problem before attempt is made to write structure that would be an Object at dataformat level.

However, I think the idea that in absence of other functionality to "flatten" Objects (like, "any properties", or nested/dotted notation) there should be a placeholder to use instead makes sense.

@jmatthewpryor
Copy link

What about the idea of support dot notation in the schema?

CsvSchema schema = CsvSchema.builder()
        .addColumn("person.firstName")
        .addColumn("person.firstName")
        .addColumn("person.age", CsvSchema.ColumnType.NUMBER)
        .build();

Could that work for writing CSV?

Any code pointers to places to investigate/test further would be appreciated

@jmatthewpryor
Copy link

Apologies I can see issue #9 is the place for this discussion

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