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 HttpMessageConverter [SPR-15457] #20018

Closed
spring-projects-issues opened this issue Apr 18, 2017 · 4 comments
Closed

Csv HttpMessageConverter [SPR-15457] #20018

spring-projects-issues opened this issue Apr 18, 2017 · 4 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

Julien Bouyoud opened SPR-15457 and commented

Hi,

I'd like to submit a new HttpMessageConverter in spring-web module wich handle csv format.

Since csv is a schema like format, we needs to define it for each web-ressource.
Indeed, you may have multiple endpoints with same input data.

This purpose of this feature is to give to spring needed beans to defines those structured outputs.
I also suggest an implementation based on supra-csv library.
For now, this implementation support only serialization.
As exentention, i think it should be possible to move those schema definition by annotations (but needs more plumber to do this).

If you thinks this feature could be a part of spring-web, i can push a PR with those things.

Regards,
Julien


Reference URL: https://github.com/jBouyoud/spring-framework/tree/SPR-15457

@spring-projects-issues
Copy link
Collaborator Author

Brian Clozel commented

We already have an extensive support of Jackson - what do you think about jackson-dataformats-text CSV in that case? Wouldn't it require much less specific code in Spring Framework's codebase since the CSV schema is handled by Jackson itself (via annotations or a builder pattern)?

I don't see a lot of activity on this library, nor new releases planned at the moment.

I'll leave this issue opened for now and we'll see if other Spring developers think this might be useful and what library they've chosen.
Votes, comments describing actual use cases should help!

Thanks for your contribution!

@spring-projects-issues
Copy link
Collaborator Author

Julien Bouyoud commented

Unfortunately, I have no real experience with jackson-dataformats-text CSV.
As my opinion, I think that is a little bit strange to configure csv exports through @Json... annotations.
The major issue that I found in jackson-csv that is not support traversing object graph, so you need a DTO class definition of each exports and map your beans to those DTO before each export.

Otherwise, it could replace super-csv as well.
I think it's possible to refactor CsvMessage graph to be agnostic to the serialization library.

The purpose of this code base aims to answer to the following use cases :

  • Handle huge amount of data with java8 Stream support
  • Handle multiple schema in one file (called blocks)
    Eg: Data and then a block with data summaries
  • Handle multiple (and dynamic) schema for one object graph

I hope this help
Julien

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: web Issues in web modules (web, webmvc, webflux, websocket) labels Jan 11, 2019
@plamentotev
Copy link

plamentotev commented Feb 24, 2020

Hi,

We are looking into implementing CSV HttpMessageConverter using jackson-dataformats-text. Similar to the way MappingJackson2SmileHttpMessageConverter and MappingJackson2CborHttpMessageConverternd are implemented.

If you think that it might be useful to have Jackson CSV support in Spring we can provide merge request. But there are some caveats. Jackson Dataformat CSV has some limitations. Most importantly, as @jBouyoud mentioned, it does not support deeply nested structures. In other words you can't just return any POJO. It needs to be "flat". In our use case that is ok, because we have a separate endpoints that returns only CSV so we can have flat DTO specifically for this endpoint. But it may not work as expected if applied to all endpoints in a service. If you apply it to average RestController, chances are that exception will be thrown because the returned type is nested and thus not supported by Jackson Dataformat CSV. That is why I'm not sure if it is "generic" enough to be included as HttpMessageConverter in Spring. What do you think?

Another caveat is that the ObjectWriter returned by CsvMapper is not reusable for different classes. My understanding is that you need separate ObjectWriter for each class you serialize because you need to provide a schema for the serialization and the schema is type specific.

@bclozel
Copy link
Member

bclozel commented Dec 1, 2023

There hasn't been many requests for this feature over the last years. I believe that our existing AbstractJackson2HttpMessageConverter, AbstractJackson2Decoder and AbstractJackson2Encoder provide a good basis for writing your own codec for the CSV format. We even added a simple version of that in a test recently written for #30493.

We don't aim to provide codecs for the numerous formats supported by Jackson and other libraries. Instead we can implement the infrastructure here in Spring Framework to unlock such cases.

I'm closing this issue as a result. Thanks for your contribution!

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Dec 1, 2023
@bclozel bclozel added the status: declined A suggestion or change that we don't feel we should currently apply label Dec 1, 2023
@bclozel bclozel removed this from the General Backlog milestone Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants