json - 收到不支持的媒体类型错误

标签 json rest spring-boot

您好,我正在使用 Rest 客户端,即 Postman 发送 REST 请求,但出现错误:

{
    "timestamp": 1432829209385,
    "status": 415,
    "error": "Unsupported Media Type",
    "exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
    "message": "Content type 'text/plain;charset=UTF-8' not supported",
    "path": "/api/v1/user"
}

我的 Controller 是:

@RequestMapping(value = "/user", method = RequestMethod.PUT, produces = "application/json")
    public Map<String,Object> updateUser(@RequestBody @Valid User user) {
//      userService.updateUser(user);
        return ResponseHandler.generateResponse("", HttpStatus.ACCEPTED, false, null);
    }

我正在通过 REST 客户端发送如图所示的请求。

enter image description here

最佳答案

将 Postman 中的 Content-Type 更改为 application/json。单击标题按钮即可执行此操作。

此外,您没有在该方法中生成 json。从注释中删除 products="application/json"

关于json - 收到不支持的媒体类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30511911/

相关文章:

java - 在使用 @JsonValue 反序列化类时,Jackson 更喜欢私有(private)构造函数而不是 @JsonCreator

javascript - React 渲染 FusionChart 使用 API Rest

rest - 如何设计 REST API 来获取大型(临时)数据流?

java - com.fasterxml.jackson.databind.exc.InvalidDefinitionException : No serializer found

spring-boot - 在junit5中使用SpringRunner有什么特别的配置吗?

java - 如何使用带注释的查询让 PageRequest 在 Spring Boot 中工作

jquery - 是否可以根据 json 值评级星级?

ruby-on-rails - 错误无法在 Windows 7x64 上构建 json gem native 扩展

java - JSON 文件 - Java : editing/updating fields values

具有两个不同 key 的实体的 REST API URI