Use Gson to serialize a POJO

I use GSON serialize POJO -- both the object before and after altered. The altered one (call it A) which is setup by Struts2 could easily serialized to Json. While the POJO before altered which is get from database via iBatis (call it B) couldn't be serialized. The error message says: Forgot to register a type adapter? I have read the Gson API. But I don't think register a type adapter for every POJO is a good idea.What makes the B couldn't be serialized? I write a clone() for my POJO, and the object cloned from B could be done also. This is confusing... Is there anybody could answer me? before altered(B's clone): {"id":"6429B5329C544711A9848AF243D10E4E","idType":"未选择","firstDate":"Feb 29, 2012 12:00:00 AM","name":"testetes","gender":"男","phone":"553223","city":"未选择","ocup":"未选择","nation":"未选择","famStru":"未选择","infSouc":"未选择","creater":"EE4783A6272A4B62A5CC68DB3C11FE1E","createDate":"Feb 29, 2012 12:00:00 AM","purpose":"未选择","education":"未选择","income":"未选择","cars":"未选择","acptCarpRent":"未选择","acptCarpPrice":"未选择","handStand":"未选择","intentHouse":"未选择","intentArea":"未选择","intentLayout":"未选择","nextDate":"Mar 7, 2012 12:00:00 AM","wuyeType":"未选择","attentionPro":"958B9E093A84415B901900C2DA25C712","ordinaryTraffic":"未选择","attentionPoint":"未选择","buyDate":"未选择","cityArea":"未选择","lastUpdate":"Feb 29, 2012 12:00:00 AM","lastModifier":"EE4783A6272A4B62A5CC68DB3C11FE1E","saler":"A4FB4877DC2945E980477544A955B57F","state":"意向","status":"0"} After altered(A): {"id":"6429B5329C544711A9848AF243D10E4E","idType":"未选择","firstDate":"Feb 29, 2012 12:00:00 AM","visitMode":"","name":"testetes","gender":"男","telPhone":"","phone":"553223","fax":"","adrs":"","postCode":"","email":"","workUnit":"","city":"未选择","media_id":"","ocup":"未选择","idNum":"","nation":"未选择","famStru":"未选择","infSouc":"未选择","createDate":"Feb 29, 2012 12:00:00 AM","idAdr":"","purpose":"未选择","education":"未选择","income":"未选择","cars":"未选择","acptCarpRent":"未选择","acptCarpPrice":"未选择","handStand":"未选择","intentHouse":"未选择","intentArea":"未选择","intentLayout":"未选择","customerDetail":"","wuyeType":"未选择","attentionPro":"958B9E093A84415B901900C2DA25C712","ordinaryTraffic":"未选择","attentionPoint":"未选择","buyDate":"未选择","cityArea":"未选择","lastUpdate":"Mar 11, 2012 2:58:04 PM","lastModifier":"00000000000000000000000000000000","saler":"A4FB4877DC2945E980477544A955B57F","state":"意向"}
Please post the two JSON strings as well the output in both cases.

以上就是Use Gson to serialize a POJO的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏