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

Cannot serialize a list of beans into CSV format using JacksonRepresentation #928

Open
thboileau opened this issue Jul 4, 2014 · 1 comment

Comments

@thboileau
Copy link
Contributor

thboileau commented Jul 4, 2014

as reported here http://stackoverflow.com/questions/24569318/writing-multi-line-csv-with-jacksonrepresentation, the current JacksonRepresentation does not take into account correctly the serialization of collection of beans to CSV format.
The objectWriter is not correctly set, and in addition it can't be correctly overriden by specifying the csv schema.

As workaround:

rep = new JacksonRepresentation<MyBean[]>(MediaType.TEXT_CSV, tab) {
    @Override
    protected ObjectWriter createObjectWriter() {
        CsvMapper csvMapper = (CsvMapper) getObjectMapper();
        CsvSchema csvSchema = csvMapper.schemaFor(MyBean.class);
        ObjectWriter result = csvMapper.writer(csvSchema);
        return result;
    }
};
@thboileau thboileau self-assigned this Jul 4, 2014
@jlouvel jlouvel modified the milestone: Unplanned Nov 2, 2014
@thboileau
Copy link
Contributor Author

thboileau commented May 5, 2016

simpler way:

new JacksonRepresentation<List<MyBean>>(MediaType.TEXT_CSV, array) {
    @Override
    protected CsvSchema createCsvSchema(CsvMapper csvMapper) {
        return csvMapper.schemaFor(MyBean.class);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants