net.sf.ezmorph.bean.MorphDynaBean cannot be cast to com.console.demo.web.model.XXX
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相关推荐
- net.sf.ezmorph.bean.MorphDynaBean cannot be cast to
前端传输数据格式: {"foodStoreId":"28", "supplyTime":2,"exList":[{&qu ...
- net.sf.ezmorph.bean.MorphDynaBean cannotbe cast to xxx
net.sf.ezmorph.bean.MorphDynaBean cannotbe cast to xxx 在操作json的数据格式的时候,如果没有指明数据类型,那么只能是基本类型或者是String ...
- JSON字符串转换object错误:MorphDynaBean cannot be cast to com.softright.bean.TestBean,类中有集合类型的属性...
今天遇到个错误 因为JSONObject.toBean()把JSON字符串转换为一个自己定义的类,当其中属性有类似List , Map ,ArrayList的时候,麻烦就来了 错误:MorphDyna ...
- 出现java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher错误
转载自:http://www.blogjava.net/lsshap/archive/2009/11/16/302602.html JSON 即 JavaScript Object Natation, ...
- 出现java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher
JSON 即 JavaScript Object Natation,它是一种轻量级的数据交换格式,非常适合于服务器与 JavaScript 的交互.本文将快速讲解 JSON 格式,并通过代码示例演示如 ...
- JSON调试找不到 net.sf.ezmorph.Morpher问题解决
JSON中,java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher问题解决 使用JSON,在SERVLET或者STRUTS的ACTION中取得数 ...
- JSON中,java.lang.NoClassDefFoundError: net/sf/ezmorph/Morpher问题解决
http://blog.csdn.net/lalalove_yaya/article/details/3129834 使用JSON,在SERVLET或者STRUTS的ACTION中取得数据时,如果会出 ...
- net.sf.ezmorph.Morpher问题解决
运行web项目,外部访问Servlet报错 报错如下: nested exception is java.lang.NoClassDefFoundError: net/sf/ezmorph/Morph ...
- java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher
java.lang.ClassNotFoundException: net.sf.ezmorph.Morpher 出现以上异常,可能是使用Json缺少ezmorph包: 以下是Json常用的包: ...
最新文章
- python中tkinter圆弧_Tkinter(Python)中弧的选项
- android判断是否json格式,Android判断json格式将错误信息提交给服务器
- .NET 正则表达式’$’符号的使用
- 144. Binary Tree Preorder Traversal
- SpringMVC中利用HandlerExceptionResolver完成异常处理
- 微型计算机的外存储器可与 直接打交道,微型计算机的外存储器可与( )直接打交道。...
- python列表生成多个号码_python遍历多个列表生成列表或字典
- Leetcode--542. 01 矩阵(java)
- 7-5 表达式转换 (18 分)
- Pytorch专题实战——数据转换(Dataset Transforms)
- mssql sql server 其它系统函数 parsename 点语法字符串分割函数应用简介
- java实现人脸识别(附源码)
- 酒店管理系统-需求说明书
- 30个值得推荐的数据可视化工具(2022年最新)
- python的if条件语句的用法及实例
- 华为盒子-悦MEC6108V9C-强刷固件-4.4.2版本
- 5G学习之路——认识CU、DU
- 微信CRM六大模块详解
- 齐岳:环糊精修饰Fe3O4磁性纳米复合材料|十二烷基硫酸钠(SDS)将Fe3O4磁性纳米粒子定量地修饰到多壁碳纳米管
- cocos2d-x ui::Button 的setEnabled 和 setVisible 的区别,setEnabled后按钮却不见了