我想
{
"male": {
"id": "0001",
"name": "Emma",
"pet": "dog"
},
"female": {
"id": "0001",
"name": "Cilia",
"pet": "cat"
}
}
使用 spring boot @RequestBody 注释将此 JSON 结构绑定到 java HashMap 数据结构。但是,spring boot 无法绑定它,但是如果我将 json 作为字符串接收并手动将其绑定到 hashmap 它将成功。她是HashMap
public class Tickets {
private HashMap<String, PeopleType> peopleTypes = new HashMap();
}
public class PeopleType {
private String id;
private String name;
private String pet;
}
这是控制器
@PostMapping("/url")
public ResponseEntity bookTickets(@RequestBody Tickets tickets, HttpSession session) {
...
}
为简洁起见,我删除了所有 Getter 和 Setter