【发布时间】:2023-03-04 16:55:01
【问题描述】:
我正在通过 Web 服务读取以下 json。有没有办法将 json 读入三个合适的 POJO? POJO 由 hibernate 生成,用于与数据库通信。
基本上我需要将person json 读入Person POJO,将pets json 读入一组Pet POJO,并将toy json 读入一组Toy POJO。
JSON
{
"person":{"first_name":"John", "last_name":"Smith"},
"pets":[{"species":"dog", "name":"Adama"}, {"species":"cat", "name":"Benton"} ],
"toys":[{"car":"corvet", "color":"black"}, {"action_figure":"hancock", "height":"1ft"} ]
}
网络服务
@Post
public Representation readForm(Representation representation) {
try {
Person aPerson = …
Set<Pet> petSet = …
Set<Toy> toySet = ...
….
【问题讨论】:
标签: json hibernate pojo restlet-2.0