0

is there a way an incoming text/plain contant type which contains a valid JSON doc can be received automatically into a bean DTO/Model

Right now I am having to receive as a string and then use an Object Mapper (see far below). When I tried to use a bean in the signature it gave

{
    "type": "https://www.jhipster.tech/problem/problem-with-message",
    "title": "Unsupported Media Type",
    "status": 415,
    "detail": "Content type 'text/plain;charset=UTF-8' not supported",
    "path": "/api/circle/notification",
    "message": "error.http.415"
} 
    @PostMapping(path = "/circle/notification", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE}, consumes = {MediaType.TEXT_PLAIN_VALUE})
    public String event(@RequestBody String notification) throws URISyntaxException {
        log.debug("REST request to post Circle notification : {}", notification);
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode root = objectMapper.readTree(notification);
            log.debug("json root : {}", root.toString());

        } catch (Exception ex) {
            log.error("notification error {}", ex.toString());
        }


        return "OK";
    }
1977
  • 2,580
  • 6
  • 26
  • 37
  • See if my first answer edit 2 helps [here](https://stackoverflow.com/a/66798610/1712172) – code_mechanic Mar 26 '21 at 03:10
  • in myy case I am receiving a json body (not query params) but the folks that send the json have set the content type to text/plain for some reason. What I have above works but its so nasty – 1977 Mar 26 '21 at 19:39

0 Answers0