java jsonobject date_如何将Json Passed Date Value分配给Java Date Object
我的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对象有什么问题
java jsonobject date_如何将Json Passed Date Value分配给Java Date Object相关推荐
- js ajax 访问java函数,将url分配给Java EE项目中的ajax(js)函数
我正在Ajax中尝试使用我的第一个项目,并且在分配指向要从服务器中获取的文件的绝对URL时遇到问题.将url分配给Java EE项目中的ajax(js)函数 这是我的函数: function fetc ...
- json:JSONObject包的具体使用(JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包)...
1.JSONObject介绍 JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包. 2.下载jar包 http:// ...
- java.lang.ClassCastException: cn.hutool.json.JSONObject cannot be cast toXXXX
java.lang.ClassCastException: cn.hutool.json.JSONObject cannot be cast toXXXX 除了网上常见解决方案以外,也存在另一种可能导 ...
- java resultset转json_ResultSet到JSON的最有效转换?
以下代码ResultSet使用JSONArray和将转换为JSON字符串JSONObject. import org.json.JSONArray; import org.json.JSONObjec ...
- java调用天气API和JSON解析的那些事儿
人丑话不多: 直接上代码: 1.根据返回的json数据格式定义数据模型 import java.util.List;//定义一个描述天气的类 public class WeatherForecastI ...
- java curl json_POST请求发送json数据java HttpUrlConnection
我开发了一个java代码,使用URL和HttpUrlConnection将以下cURL转换为java代码.卷曲是: curl -i 'http://url.com' -X POST -H " ...
- Json学习总结(1)——Java和JavaScript中使用Json方法大全
2019独角兽企业重金招聘Python工程师标准>>> 摘要:JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript ...
- JSONObject 和 GSON 解析 JSON 数据详解(转)
转载:http://www.jianshu.com/p/f99de3ec0636 点此进入:从零快速构建APP系列目录导图 点此进入:UI编程系列目录导图 点此进入:四大组件系列目录导图 点此进入:数 ...
- Java中含有泛型的 JSON 反序列化问题
作者:明明如月学长 blog.csdn.net/w605283073/article/details/107350113 一.背景 今天无聊之园提了一个问题,涉及的示例大致如下: public st ...
最新文章
- Silverlight 游戏开发小技巧:角色升级特效
- 八百客与51CTO结了梁子?
- IAR编译提示could not open file lnkstm8s003f3.icf
- (转载)netstat -r查看路由表时Flags的含义
- linux关机命令详解
- 2. Add Two Numbers(Leetcode)
- BM惊爆:EOS一周年工作KPI
- gsoap(C/C++调用webservice)
- 在Windows下基于libx264.a的Qt 4.8.2视频压缩
- C#中泛型类型约束条件
- php preg_match_all匹配正则,字符串过长时出错
- 一个小技巧让你轻松处理Selenium处理滚动条和元素聚焦
- 缓存穿透-布隆过滤器
- MyBatis的ResultMaps之一对多关系
- 2017滴滴校招 末尾0的个数(数学知识)
- 影像组学训练营 第三天(共三天)
- 1459. 奶牛体操
- unity火焰粒子效果
- Excel的常用查询函数一(Index与match联合查询)
- 淘宝短视频多模态融合识别
热门文章
- 问题解决: 此文件来自其他计算机,可能被阻止以帮助保护该计算机/WORD在试图打开文件时遇到错误……
- 异常:java.lang.NoSuchMethodError: org.apache.poi.ss.usermodel.Workbook.getCellStyleAt
- 解决 Chrome 下载不了东西 失败 - 已屏蔽 的问题
- 带参数的RedirectToAction
- 计算机等级ms答题演示,计算机等级一级MS Office考试考题:第六套演示文稿题
- c语言中0xa0f对应的十进制,全国计算机二级C基础知识重点讲解
- mybatis动态sql传ist集合參与传数组参数
- android对话框合集AlertDialog
- c++ string 长度限制_面试中要会的String相关问题
- MTK:内存管理机制简单分析