【发布时间】:2014-07-24 10:46:27
【问题描述】:
我有实体类:
@Entity
@Table(name="person")
public class Person implements Serializable {
@Id @Column(unique=true)
private int id;
private String title;
// getter, setter, constructor,...
}
在控制器中:
@RequestMapping(value="/get/{id}", method=RequestMethod.GET)
public @ResponseBody Person getPerson(@PathVariable int id) {
return personManager.findById(id);
}
@RequestMapping(value="/add", method=RequestMethod.POST)
public @ResponseBody void addPerson(@RequestBody Person person) {
String log = parse_json_from_input("log"); // How can I do it?
// do something with log
personManager.save(person);
}
我想以 JSON 格式发送附加参数并对其进行解析。如果我执行以下命令,我会得到 Person 实体 - 没关系。但我需要在addPerson 方法中获取log 属性以供其他用途。
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" \
-d '{"title":"abc","log":"message..."}' http://localhost:8080/test/add
如何解析它?
【问题讨论】:
标签: java json spring rest jackson