更新时间:2023-02-23 14:00:34
使用JsonNode
.
只需对hotel_data
的POJO中的字段checkinCheckoutTimes
进行以下操作setter
,它便会为您工作.
Just make the following setter
for the field checkinCheckoutTimes
in your POJO for hotel_data
and it should work for you.
public void setCheckinCheckoutTimes(JsonNode node) {
this.checkinCheckoutTimes = node.toString();
}
String str = "{ \"id\": 1, \"data\": { \"a\": 1 } }";
try {
System.out.println(new ObjectMapper().readValue(str,Employee.class));
} catch (IOException e) {
e.printStackTrace();
}
其中Employee
如下:
class Employee
{
private int id;
private String data;
public Employee() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getData() {
return data;
}
public void setData(JsonNode node) {
this.data = node.toString();
}
@Override
public String toString() {
return "Employee{" +
"id=" + id +
", data='" + data + '\'' +
'}';
}
}
给出以下输出:
Employee{id=1, data='{"a":1}'}