从JSON转换为Java对象

时间:2016-09-29 18:41:21

标签: java json object jackson

我正在尝试使用jackson将JSON转换为java对象。但我得到空值。这是我的pojos。请注意,我在这2个班级都有安装人员和吸气员。

@JsonIgnoreProperties(ignoreUnknown = true)
public class IncidentDetails {

    private Integer incidentTypeId;
    private String description;
    private List<IncidentEvents> incidentEventList;
@JsonIgnoreProperties(ignoreUnknown = true)
public class IncidentEvents {

    private int eventId;
    private int alarmId;
    private Timestamp eventDateTime;

}
My Request: 
{
  "IncidentDetails": {
    "incidentTypeId": "1",
    "description": "Description",
    "IncidentEvents": 
      [
        {
          "eventId": "1",
          "alarmId": "1",
          "eventDateTime": "09/29/2016 12:00:00 AM"
        },
        {
          "eventId": "2",
          "alarmId": "2",
          "eventDateTime": "09/29/2016 12:05:00 AM"
        }
      ]
  }
}

我如何映射它:

ObjectMapper mapper = new ObjectMapper();
IncidentDetails incident = mapper.readValue(details, IncidentDetails.class);
.....

0 个答案:

没有答案