Spring RestController endpoint that consumes and produces a String value returning "HTTP Status 415 – Unsupported Media Type"

Viewed 25

I'm trying to setup a fairly simple endpoint that takes in String and produces a String. I've simplified it down to:

@RequestMapping(value="/foo",
        method = RequestMethod.GET,
        consumes = MediaType.TEXT_PLAIN_VALUE,
        produces= MediaType.TEXT_PLAIN_VALUE)
public String foo(@RequestBody String data) {
    return data;
}

I'm testing with Postman and am just getting "HTTP Status 415 – Unsupported Media Type" back. This app is running on Spring 4.1.3. I copied this endpoint into another project I have in Spring Boot, using my same Postman request (just modified the host), and it works there. So there appears to be some issue with the version of Spring this project uses. As a work-around I created a simple wrapper entity (POJO that only consists of a single String) and changed the endpoint to consume JSON/this POJO. Does anyone know specifically why it doesn't work as above and/or know of a workaround that'll let me send and receive a plain text String with this version of Spring?

0 Answers
Related