我的Java POJO类是
public class Task implements java.io.Serializable {
private Integer id;
private Date startDate;
private Date endDate;
private Integer priority;
private Double duration;
private Integer percentDone;
private String durationUnit;
private Integer parentId;
private String taskName;
private Integer taskindex;
private Integer depth;
public Task() {
}
public Task(Date startDate, Date endDate, Integer priority,
Double duration, Integer percentDone, String durationUnit,
Integer parentId, String taskName, Integer taskindex, Integer depth) {
this.startDate = startDate;
this.endDate = endDate;
this.priority = priority;
this.duration = duration;
this.percentDone = percentDone;
this.durationUnit = durationUnit;
this.parentId = parentId;
this.taskName = taskName;
this.taskindex = taskindex;
this.depth = depth;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "Id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Temporal(TemporalType.DATE)
@Column(name = "StartDate", length = 10)
public Date getStartDate() {
return this.startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
@Temporal(TemporalType.DATE)
@Column(name = "EndDate", length = 10)
public Date getEndDate() {
return this.endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
@Column(name = "Priority")
public Integer getPriority() {
return this.priority;
}
public void setPriority(Integer priority) {
this.priority = priority;
}
@Column(name = "Duration", precision = 22, scale = 0)
public Double getDuration() {
return this.duration;
}
public void setDuration(Double duration) {
this.duration = duration;
}
@Column(name = "PercentDone")
public Integer getPercentDone() {
return this.percentDone;
}
public void setPercentDone(Integer percentDone) {
this.percentDone = percentDone;
}
@Column(name = "DurationUnit", length = 20)
public String getDurationUnit() {
return this.durationUnit;
}
public void setDurationUnit(String durationUnit) {
this.durationUnit = durationUnit;
}
@Column(name = "parentId")
public Integer getParentId() {
return this.parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
@Column(name = "TaskName")
public String getTaskName() {
return this.taskName;
}
public void setTaskName(String taskName) {
this.taskName = taskName;
}
@Column(name = "Taskindex")
public Integer getTaskindex() {
return this.taskindex;
}
public void setTaskindex(Integer taskindex) {
this.taskindex = taskindex;
}
@Column(name = "depth")
public Integer getDepth() {
return this.depth;
}
public void setDepth(Integer depth) {
this.depth = depth;
}我的util将分配值从我的jsonObject到Pojo是
JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(new String[] {"yyyy-MM-dd'T'HH:mm:ss"}));
JSONObject jsonObject = JSONObject.fromObject(data);
System.out.println("JSON OBJECT VALUE FOR PARENTID ::"+jsonObject.get("parentId"));
jsonObject.put("taskName", jsonObject.getString("Name"));
jsonObject.put("startDate", jsonObject.get("StartDate"));
jsonObject.put("endDate", jsonObject.get("EndDate"));
jsonObject.put("duration", jsonObject.getInt("Duration"));
jsonObject.put("durationUnit", jsonObject.getString("DurationUnit"));
jsonObject.put("percentDone", jsonObject.getInt("PercentDone"));
jsonObject.put("priority", jsonObject.getInt("Priority"));
jsonObject.put("parentId", jsonObject.getInt("parentId"));
jsonObject.put("taskindex", jsonObject.getInt("index"));
jsonObject.put("depth", jsonObject.getInt("depth"));
jsonObject.remove("Id");
jsonObject.remove("ManuallyScheduled");
jsonObject.remove("checked");
jsonObject.remove("Name");
jsonObject.remove("StartDate");
jsonObject.remove("EndDate");
jsonObject.remove("Duration");
jsonObject.remove("DurationUnit");
jsonObject.remove("PercentDone");
jsonObject.remove("Priority");
jsonObject.remove("index");
System.out.println("JSON OBJECT ::"+jsonObject);
Task newTask = (Task) JSONObject.toBean(jsonObject, Task.class);和我接收到我的服务器端的jsonObject是
{
"parentId": 0,
"depth": 1,
"taskName": "New Task",
"startDate": "2012-01-30T00:00:00",
"endDate": "2012-01-31T00:00:00",
"duration": 1,
"durationUnit": "d",
"percentDone": 60,
"priority": 1,
"taskindex": 5 }不知道为什么我无法将startDate分配给我的startDate POJO对象。
当我删除JSONUtils.getMorpherRegistry()。registerMorpher(new DateMorpher(new String [] {“yyyy-MM-dd'T'HH:mm:ss”}));
值分配给我的POJO对象,一切正常,但startDate更改为当前日期,然后它被分配。我正在向我的服务器端发出警告
WARNING: Can't transform property 'startDate' from java.lang.String into java.util.Date. Will register a default Morpher INFO: Property 'java.util.Date.class' has no write method. SKIPPED. WARNING: Property 'java.lang.String.date' does not exist. SKIPPED. INFO: Property 'java.util.Date.day' has no write method. SKIPPED. WARNING: Property 'java.lang.String.hours' does not exist. SKIPPED. WARNING: Property 'java.lang.String.minutes' does not exist. SKIPPED. WARNING: Property 'java.lang.String.month' does not exist. SKIPPED. WARNING: Property 'java.lang.String.seconds' does not exist. SKIPPED. INFO: Property 'java.util.Date.timezoneOffset' has no write method. SKIPPED.在此之后,当我打印POJO赋值时,我将获得startDate作为2012年1月12日10:09:27 IST和endDate作为星期四2012年1月12日10:09:27 IST
那么将jsonObject分配给我的Pojo Date对象有什么问题