Spring Rest POST Json RequestBody Content type not supported

后端 未结 14 1716
粉色の甜心
粉色の甜心 2020-12-05 05:58

When I try to post new object with post method. RequestBody could not recognize contentType. Spring is already configured and POST could work with others objects, but not th

14条回答
  •  余生分开走
    2020-12-05 06:49

    I met the same problem which i solved by deserializing myself the posted value :

    @RequestMapping(value = "/arduinos/commands/{idArduino}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String sendCommandesJson(@PathVariable("idArduino") String idArduino, HttpServletRequest request) throws IOException {
        // getting the posted value
        String body = CharStreams.toString(request.getReader());
        List commandes = new ObjectMapper().readValue(body, new TypeReference>() {
        });
    

    with theses gradle dependencies :

      compile('org.springframework.boot:spring-boot-starter-web')
      compile('com.google.guava:guava:16.0.1')
    

提交回复
热议问题