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

ColumnPositionMappingStrategy: need to set type manually #7

Closed
kryger opened this issue Apr 28, 2014 · 3 comments
Closed

ColumnPositionMappingStrategy: need to set type manually #7

kryger opened this issue Apr 28, 2014 · 3 comments

Comments

@kryger
Copy link

kryger commented Apr 28, 2014

As mentioned in #6 it took me some time to get BeanToCsv writer to work, only after analysing in the debugger I discovered that type variable inside HeaderColumnNameMappingStrategy (code) is not being set, I had to do it manually:

BeanToCsv<Institution> beanWriter = new BeanToCsv<>();
try (Writer printWriter = new PrintWriter(System.out)) {
    ColumnPositionMappingStrategy<Institution> strategy = new ColumnPositionMappingStrategy<>();
    strategy.setType(Institution.class); // the surprising line
    strategy.setColumnMapping(new String[] { "name", "email", "url" });
    beanWriter.write(strategy, printWriter, institutions);
}

This feels redundant, would be nice if the strategy object set it automatically upon construction.

@quux00
Copy link
Owner

quux00 commented Apr 29, 2014

Sounds good. Usually in Java that would be solved via the constructor, like so:

ColumnPositionMappingStrategy<Institution> strategy = 
  new ColumnPositionMappingStrategy<Institution>(Institution.class);

so I think that would be a good addition.

quux00 added a commit that referenced this issue Apr 29, 2014
…onstructor.

Added new tests and modified existing ones for the various MappingStrategy
classes used with BeanToCsv.
@quux00
Copy link
Owner

quux00 commented Apr 29, 2014

Just pushed a commit to add this constructor to all the MappingStrategies. Added new tests as well. Let me know if this works for you.

@kryger
Copy link
Author

kryger commented Apr 29, 2014

Thanks for quick reaction, will give it a try when I get a chance. Closing this issue to keep things clean, will reopen if needed.

@kryger kryger closed this as completed Apr 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants