How to add csv MimeType to spring content-negotiation?

membersound

I'm creating a webservice method that can serve xml, json and csv output:

@GetMapping(produces = {APPLICATION_XML_VALUE, APPLICATION_JSON_VALUE, "text/csv"})
public Rsp get() {
}

Problem: I somehow need to add the text/csv content type to my configureContentNegotiation(). But how? Because a String is not accepted, and a MediaType.TEXT_CSV does not exist (even though RFC7111 defines it as a valid mimetype.

@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer
                .favorParameter(true)
                .mediaType("json", MediaType.APPLICATION_JSON)
                .mediaType("xml", MediaType.APPLICATION_XML)
                .mediaType("csv", "text/csv"); //this is invalid
    }
}
membersound
.mediaType("csv", new MediaType("text", "csv"));

or even configure as follows in application.properties:

spring.mvc.media-types.json=application/json
spring.mvc.media-types.xml=application/xml
spring.mvc.media-types.csv=text/csv

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Use Content Negotiation in Spring Data Rest?

From Dev

How to disable content negotiation for Spring Actuators?

From Dev

How to Use Content Negotiation in Spring Data Rest?

From Dev

Spring boot controller content negotiation

From Dev

Spring MVC Content Negotiation throwing ClassCastException

From Dev

Is there a simple way to solve content negotiation in Spring boot

From Dev

spring cloud config-server .properties content-negotiation failing

From Dev

Is there better approach to Accept Header based content negotiation in Spring API?

From Dev

How to add a mimetype icon in the home directory?

From Dev

How to add a mimetype icon in the home directory?

From Dev

Content negotiation to return HTML

From Dev

PhalconPHP: content negotiation?

From Dev

Restlet Content Type Negotiation

From Dev

Content negotiation using WebSharper

From Dev

PhalconPHP: content negotiation?

From Dev

Python: add a new mimetype

From Dev

Jersey - content negotiation for error handling

From Dev

How add Static Web Content in Spring-boot

From Dev

How to add content to an Spring oauth2 access token?

From Dev

How to get the mimetype of an item?

From Dev

SupportedMediaTypes not used when doing content negotiation

From Dev

Why not use content negotiation to return JSON object?

From Dev

Content Negotiation when looking at different output formats

From Dev

Content negotiation for File Download In Web API

From Dev

Content negotiation not working with respond_to stanza

From Dev

What is performing Transparent Content Negotiation in Apache

From Dev

ServiceStack Plugin How to add MimeType for new file suffix, and allow the file suffix to be served?

From Dev

How to get intent filter MimeType

From Dev

How to use mimeType Assert with VichUploader?

Related Related

  1. 1

    How to Use Content Negotiation in Spring Data Rest?

  2. 2

    How to disable content negotiation for Spring Actuators?

  3. 3

    How to Use Content Negotiation in Spring Data Rest?

  4. 4

    Spring boot controller content negotiation

  5. 5

    Spring MVC Content Negotiation throwing ClassCastException

  6. 6

    Is there a simple way to solve content negotiation in Spring boot

  7. 7

    spring cloud config-server .properties content-negotiation failing

  8. 8

    Is there better approach to Accept Header based content negotiation in Spring API?

  9. 9

    How to add a mimetype icon in the home directory?

  10. 10

    How to add a mimetype icon in the home directory?

  11. 11

    Content negotiation to return HTML

  12. 12

    PhalconPHP: content negotiation?

  13. 13

    Restlet Content Type Negotiation

  14. 14

    Content negotiation using WebSharper

  15. 15

    PhalconPHP: content negotiation?

  16. 16

    Python: add a new mimetype

  17. 17

    Jersey - content negotiation for error handling

  18. 18

    How add Static Web Content in Spring-boot

  19. 19

    How to add content to an Spring oauth2 access token?

  20. 20

    How to get the mimetype of an item?

  21. 21

    SupportedMediaTypes not used when doing content negotiation

  22. 22

    Why not use content negotiation to return JSON object?

  23. 23

    Content Negotiation when looking at different output formats

  24. 24

    Content negotiation for File Download In Web API

  25. 25

    Content negotiation not working with respond_to stanza

  26. 26

    What is performing Transparent Content Negotiation in Apache

  27. 27

    ServiceStack Plugin How to add MimeType for new file suffix, and allow the file suffix to be served?

  28. 28

    How to get intent filter MimeType

  29. 29

    How to use mimeType Assert with VichUploader?

HotTag

Archive