[英]how to pass custom dto as rest api input using postman rest client
Here is my code ,I'm trying to pass the user details as a json input but I'm not able to receive the data in my rest api method. 这是我的代码,我试图将用户详细信息作为json输入传递,但是我无法通过rest api方法接收数据。 I"m getting all values as null,
我将所有值都设为null,
this is my json request 这是我的json请求
{
"userId" : "12345",
"username" : "arun.ammasai",
"createdBy" : "-2",
"updatedBy" : "-2",
"statusCd" : "New",
"createdDate" : "2019-03-03",
"updatedDate" : "2019-03-03"
}
==================================================================== ================================================== ==================
@RequestMapping(value = "/registerUser", method = RequestMethod.POST, consumes = { "application/JSON", "application/XML" })
private String registerUser(User user) {
System.out.println(user.toString());
return "User Created";
}
==================================================================== ================================================== ==================
here is the response in Postman Client 这是邮递员客户端中的响应
Unexpected 'U' 意外的“ U”
Update your method signature with @RequestBody annotation. 使用@RequestBody批注更新您的方法签名。 It will automatically deserialize your json into java entity.
它将自动将json反序列化为Java实体。 Be carefull, names in json should be the same as parameters in User object and User object should have getters and setters.
请注意,json中的名称应与User对象中的参数相同,并且User对象应具有getter和setter。 So your method should look like
所以你的方法应该像
@RequestMapping(value = "/registerUser", method = RequestMethod.POST, consumes = { "application/JSON", "application/XML" })
private String registerUser(@RequestBody User user) {
System.out.println(user.toString()); //What is the reason of doing toString of java Object?
//better to do System.out.println(user.getUsername())
return "User Created";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.