I am using Postman to send a post request with the following controller (which doesn't work)
@RequestMapping(value="/updateData", method=RequestMethod.POST, consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON)
public int updateData(@RequestBody FriendInfoForm request);
and I want this type of payload to be accepted as a "request" object.
{
"name": "John",
"age": 27,
"friendList": [
{
"name": "Jack",
"age": 20
},
{
"name": "Jill",
"age": 21
}
]
}
and this is the FriendInfoForm
definition:
public class FriendInfoForm {
private String name;
private int age;
private ArrayList friendList;
(getters and setters)
}
When I try to send the post request, name
and age
get set correctly, but friendList
doesn't (it doesn't get set to anything). I can guess why (has to do with the Arraylist use).
How do I send it correctly?
you should create POJO like below class:--
public class FriendInfoForm {
private String name;
private int age;
@JsonProperty("friendList")
private List<FriendList> friendList = new ArrayList<>();;
(getters and setters)
}
public class FriendList{
private String name;
private int age;
(getters and setters)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.