我有一个端点需要读取一个字符串值作为请求体。
@RestController
public class EndpointsController {
@RequestMapping( method = RequestMethod.PUT, value = "api/{myId}/name", consumes= MediaType.APPLICATION_JSON )
public String updateName( @PathVariable( MY_ID ) String myId, @RequestBody String name) {
//will be: "new name"
//instead of : newname
return myId;
}
}
我的问题是,客户端会以正确的格式“new name”调用此内容,但由于服务器无法将字符串处理为JSON对象,因此服务器会读取带引号的内容。我该如何告诉Jackson也以同样的方式解析该字符串(就像它对Pojos所做的那样)?
@PathVariable
和 URL 中的不匹配,顺便提一下。 - Makoto