项目将com.thoughtworks.xstream升级到1.4.18遇到的问题:com。。。

项⽬将com.thoughtworks.xstream升级到1.4.18遇到问题:com。。。项⽬开发需求将xstream从1.4.17升级到1.4.18,升级后遇到了序列化问题,描述如下:
om.thoughtworks.xstream.security.ForbiddenClassException: com.jd.jcloud.wms.lp.SoOrderCancelReceipt
at com.thoughtworks.xstream.security.NoTypePermission.allows(NoTypePermission.java:26) ~[xstream-1.4.18.jar:1.4.18]
at com.thoughtworks.xstream.alClass(SecurityMapper.java:74) ~[xstream-1.4.18.jar:1.4.18]
at com.thoughtworks.xstream.alClass(MapperWrapper.java:125) ~[xstream-1.4.18.jar:1.4.18]
at com.thoughtworks.xstream.alClass(CachingMapper.java:47) ~[xstream-1.4.18.jar:1.4.18]
at com.adClassType(HierarchicalStreams.java:29) ~
[xstream-1.4.18.jar:1.4.18]
at com.TreeUnmarshaller.start(TreeUnmarshaller.java:133) ~[xstream-1.4.18.jar:1.4.18]
at com.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) ~[xstream-1.4.18.jar:1.4.18]
问题还原:
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
蜂房哈夫尼菌ca130<artifactId>xstream</artifactId>
<version>1.4.18</version>
</dependency>
代码
public static void main(String[] args){
XStream xStream =new XStream();
String xmlStr ="<receipt>\n"+
"<receiptNo>1234567</receiptNo>\n"+
"<distributeNo></distributeNo>\n"+
"<warehouseNo>123</warehouseNo>\n"+
"<erpWarehouseNo></erpWarehouseNo>\n"+
"<receiptType>123</receiptType>\n"+
"<source>123</source>\n"+
"<partnerNo>123</partnerNo>\n"+
"<clpsWarehouseNo>123</clpsWarehouseNo>\n"+
"</receipt>";
xStream.alias("receipt", SoOrderCancelReceipt.class);水产学报
xStream.ignoreUnknownElements();
SoOrderCancelReceipt soOrderReceipt =(SoOrderCancelReceipt) xStream.fromXML(xmlStr);风险投资退出机制
System.out.JSONString(soOrderReceipt));
}
结果:
Exception in thread "main" com.thoughtworks.xstream.security.ForbiddenClassException: SoOrderCancelReceipt
山东网通
at com.thoughtworks.xstream.security.NoTypePermission.allows(NoTypePermission.java:26)
at com.thoughtworks.xstream.alClass(SecurityMapper.java:74)
at com.thoughtworks.xstream.alClass(MapperWrapper.java:125)
at com.thoughtworks.xstream.alClass(CachingMapper.java:47)
at com.adClassType(HierarchicalStreams.java:29)
at com.TreeUnmarshaller.start(TreeUnmarshaller.java:133)
at com.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1391)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1376)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1261)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1252)
at Test3.main(Test3.java:35)
处理⽅案:解析之前,在前⾯添加以下两⾏代码
Class<?>[] classes =new Class[]{ SoOrderCancelReceipt.class};
xStream.allowTypes(classes);
完整代码如下:
public static void main(String[] args){
XStream xStream =new XStream();
String xmlStr ="<receipt>\n"+
"<receiptNo>123456</receiptNo>\n"+
"<distributeNo></distributeNo>\n"+
"<warehouseNo>123</warehouseNo>\n"+
常见的dna提取方法及优缺点
"<erpWarehouseNo></erpWarehouseNo>\n"+
"<receiptType>123</receiptType>\n"+
"<source>123</source>\n"+
"<partnerNo>123</partnerNo>\n"+
"<clpsWarehouseNo>123</clpsWarehouseNo>\n"+
"</receipt>";
xStream.alias("receipt", SoOrderCancelReceipt.class);
xStream.ignoreUnknownElements();
Class<?>[] classes =new Class[]{ SoOrderCancelReceipt.class};
xStream.allowTypes(classes);
SoOrderCancelReceipt soOrderReceipt =(SoOrderCancelReceipt) xStream.fromXML(xmlStr);
System.out.JSONString(soOrderReceipt));
}
执⾏结果:{"clpsWarehouseNo":"123","distributeNo":"","partnerNo":"123","receiptNo":"123456","receiptType":"123","source":123,"warehouseNo":"123"} Process finished with exit code 0

本文发布于:2024-09-14 16:24:02,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/30163.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:问题   遇到   升级   序列化   风险投资   方法   需求
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议