内容类型为'application / json; charset = UTF-8'的不受支持的媒体类型-不支持春季启动

时间:2018-08-25 12:56:34

标签: rest web-services spring-boot put

我正在尝试公开Rest服务(PUT方法)以更新实体。以下代码代表其余服务:

@PutMapping("update")
public ResponseEntity<Item> updateItem(@RequestBody Item item) {

        Item currentItem = itemService.getItembyId(item.getId());

        if(currentItem==null){
            log.error("Item with id " + item.getId() + " not found");
            return new ResponseEntity<Item>(HttpStatus.NOT_FOUND);
        }

        Item newItem = itemService.updateItem(item);

        return new ResponseEntity<Item>(newItem, HttpStatus.OK);

    } 

当我尝试通过邮递员使用它时,出现以下错误:

客户端:

  

{       “ timestamp”:“ 2018-08-25T12:42:18.108 + 0000”,       “状态”:415,       “错误”:“不支持的媒体类型”,       “ message”:“内容类型'application / json; charset = UTF-8'不支持”,       “ path”:“ / item / update”}

服务器端:

  

“” DEBUG-2018-08-25 14:42:18-书面[{timestamp = Sat Aug 25   14:42:18 CEST 2018,状态= 415,错误=不支持的媒体类型,   message =内容类型'application / json; charset = UTF-8'不支持,   path = / item / update}]作为“ application / json”使用   [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@8cc82e6]

在postaman上,我已调整以下配置以使用该服务: enter image description here enter image description here

0 个答案:

没有答案
相关问题