fastjson在反序列化时,解析对象中的继承,抽象类处理
2024-10-19 18:25:55
LimitActionConfig是ActionConfig的子类,RuleConfig的有个属性是ActionConfig,需要反序列化成LimitActionConfig
ParserConfig parserConfig = new ParserConfig() {
@Override
public ObjectDeserializer getDeserializer(Type type) {
if (type == ActionConfig.class) {
return super.getDeserializer(LimitActionConfig.class);
}
return super.getDeserializer(type);
}
}; RuleConfig ruleConfig = new RuleConfig();
ruleConfig.setDesc("xxx");
LimitActionConfig limitActionConfig = new LimitActionConfig();
limitActionConfig.setResponseContent("ddd");
ruleConfig.setActionConfig(limitActionConfig); String text = JSON.toJSONString(ruleConfig);
System.out.println(text); RuleConfig ruleConfig2 = JSON.parseObject(text, RuleConfig.class, parserConfig);
System.out.println(ruleConfig2);
参考:https://www.cnblogs.com/whitewolf/p/4355541.html
最新文章
- C# - 多线程 之 锁系统
- BZOJ1001: [BeiJing2006]狼抓兔子 [最小割 | 对偶图+spfa]
- 如何在在WinFrom的DataGridView中做到数据持续动态加载而不卡死
- CIQRCodeGenerator Core Image Filter Reference
- tableview侧滑删除
- loadrunner统计字符串中指定字符出现的次数
- mysql触发器查看
- keyStore vs trustStore--转载
- c# json转Dictionary字典
- Mac OS X平台上Java环境的配置
- Hibernate4 : 持久化你的第一个类
- overflow的几个坑
- oracle语句总结(一)
- 在VB6/VBA中使用正则表达式
- (知识点)JavaScript闭包
- chrome调试工具高级不完整使用指南(基础篇)
- vue引入fastclick设置输入框type=";number";报错Failed to execute 'setSelectionRange' on 'HTMLInputElement': The input element's type ('number') does not support selection.的解决办法
- Python 3中bytes/string的区别
- Oracle组成介绍
- 蜻蜓fm面试