2019独角兽企业重金招聘Python工程师标准>>>

前景:

net.sf.ezmorph.bean.MorphDynaBean cannot be cast to com.console.demo.web.model.XXX

//jsonObject:所有参数
//FreightTemplate对象里面包含一个 private List<FreightTemplateCity> freightTemplateCity; 类似于一父多子
FreightTemplate freightTemplate = (FreightTemplate) JSONObject.toBean(JSONObject.fromObject(jsonObject.get("freightTemplate")), FreightTemplate.class);
//先新增freightTemplate
businessDao.insertSelective(freightTemplate);
//取出子list对象
List<FreightTemplateCity> freightTemplateCities = freightTemplate.getFreightTemplateCity();
//遍历新增子对象
//PS:这句for循环报的错
for (FreightTemplateCity freightTemplateCity : freightTemplateCities) {freightTemplateCity.setTemplateId(freightTemplate.getId());businessDao.insertFreightTemplateCity(freightTemplateCity);
}

发现我的子对象自动被转换成了net.sf.ezmorph.bean.MorphDynaBean对象,找了半天不知道哪里转成这个的,于是想到直接把

JSONObject object = (JSONObject) jsonObject.get("freightTemplate");//从所有对象里取到父对象,转成JSONObject类型
JSONArray array = (JSONArray) object.get("freightTemplateCity");//从JSONObject里面取到"freightTemplateCity"转成JSONArray格式

然后JSONArray就可以直接转list了,下面贴代码

FreightTemplate freightTemplate = (FreightTemplate) JSONObject.toBean(JSONObject.fromObject(jsonObject.get("freightTemplate")), FreightTemplate.class);
//先新增freightTemplate
businessDao.insertSelective(freightTemplate);
//------------这一段转换对象类型----------------
JSONObject object = (JSONObject) jsonObject.get("freightTemplate");
JSONArray array = (JSONArray) object.get("freightTemplateCity");
List<FreightTemplateCity> list = JSONArray.toList(array, new FreightTemplateCity(), new JsonConfig());
//----------------------------
for (FreightTemplateCity freightTemplateCity : list) {freightTemplateCity.setTemplateId(freightTemplate.getId());businessDao.insertFreightTemplateCity(freightTemplateCity);
}

但是因为不知道具体发生转换的原因,不知道这样做有没有什么影响,如果有其他好的办法,望不吝啬指教一下

转载于:https://my.oschina.net/u/3526783/blog/3024439

net.sf.ezmorph.bean.MorphDynaBean cannot be cast to com.console.demo.web.model.XXX相关推荐

  1. net.sf.ezmorph.bean.MorphDynaBean cannot be cast to

    前端传输数据格式: {"foodStoreId":"28", "supplyTime":2,"exList":[{&qu ...

  2. net.sf.ezmorph.bean.MorphDynaBean cannotbe cast to xxx

    net.sf.ezmorph.bean.MorphDynaBean cannotbe cast to xxx 在操作json的数据格式的时候,如果没有指明数据类型,那么只能是基本类型或者是String ...

  3. JSON字符串转换object错误:MorphDynaBean cannot be cast to com.softright.bean.TestBean,类中有集合类型的属性...

    今天遇到个错误 因为JSONObject.toBean()把JSON字符串转换为一个自己定义的类,当其中属性有类似List , Map ,ArrayList的时候,麻烦就来了 错误:MorphDyna ...

  4. 出现java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher错误

    转载自:http://www.blogjava.net/lsshap/archive/2009/11/16/302602.html JSON 即 JavaScript Object Natation, ...

  5. 出现java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher

    JSON 即 JavaScript Object Natation,它是一种轻量级的数据交换格式,非常适合于服务器与 JavaScript 的交互.本文将快速讲解 JSON 格式,并通过代码示例演示如 ...

  6. JSON调试找不到 net.sf.ezmorph.Morpher问题解决

    JSON中,java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher问题解决  使用JSON,在SERVLET或者STRUTS的ACTION中取得数 ...

  7. JSON中,java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher问题解决

    http://blog.csdn.net/lalalove_yaya/article/details/3129834 使用JSON,在SERVLET或者STRUTS的ACTION中取得数据时,如果会出 ...

  8. net.sf.ezmorph.Morpher问题解决

    运行web项目,外部访问Servlet报错 报错如下: nested exception is java.lang.NoClassDefFoundError: net/sf/ezmorph/Morph ...

  9. java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher

    java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher  出现以上异常,可能是使用Json缺少ezmorph包:  以下是Json常用的包: ...

最新文章

  1. python中tkinter圆弧_Tkinter(Python)中弧的选项
  2. android判断是否json格式,Android判断json格式将错误信息提交给服务器
  3. .NET 正则表达式’$’符号的使用
  4. 144. Binary Tree Preorder Traversal
  5. SpringMVC中利用HandlerExceptionResolver完成异常处理
  6. 微型计算机的外存储器可与 直接打交道,微型计算机的外存储器可与( )直接打交道。...
  7. python列表生成多个号码_python遍历多个列表生成列表或字典
  8. Leetcode--542. 01 矩阵(java)
  9. 7-5 表达式转换 (18 分)
  10. Pytorch专题实战——数据转换(Dataset Transforms)
  11. mssql sql server 其它系统函数 parsename 点语法字符串分割函数应用简介
  12. java实现人脸识别(附源码)
  13. 酒店管理系统-需求说明书
  14. 30个值得推荐的数据可视化工具(2022年最新)
  15. python的if条件语句的用法及实例
  16. 华为盒子-悦MEC6108V9C-强刷固件-4.4.2版本
  17. 5G学习之路——认识CU、DU
  18. 微信CRM六大模块详解
  19. 齐岳:环糊精修饰Fe3O4磁性纳米复合材料|十二烷基硫酸钠(SDS)将Fe3O4磁性纳米粒子定量地修饰到多壁碳纳米管
  20. cocos2d-x ui::Button 的setEnabled 和 setVisible 的区别,setEnabled后按钮却不见了

热门文章

  1. 移动硬盘备份linux系统盘,将Ubuntu Linux系统放到你的移动硬盘
  2. android权限允许,android – 允许多次运行时权限
  3. java环境变量配置 - win10
  4. Tour West Australia by Motorcycle
  5. 2019 6.30学习笔记
  6. centos6.8安装httpd后无法访问
  7. 研究生学习阶段时间安排
  8. c#没有指针导致的性能问题研究一二
  9. FPGA之VGA控制
  10. 表格中内容过多时采用省略号,鼠标移上去显示全部内容