Comments (9)
这个方法的代码能看下吗?
CommonUtil.parseObject(jsonConfig, PmTopicConfig.class);
是否是类似于这个逻辑
JSONObject jsonObject = JSON.parseObject(jsonConfig);
PmTopicConfig pmTopicConfig = jsonObject.to(PmTopicConfig.class);
如果是下面这个逻辑应该没问题的
JSON.parseObject(jsonConfig, PmTopicConfig.class)
from fastjson2.
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.48-SNAPSHOT/
问题已修复,请帮忙用2.0.48-SNAPSHOT版本帮忙验证,2.0.48版本预计在3月底前发布。
from fastjson2.
@wenshao @rowstop 感谢,我看了下单元测试很全面。本来说周末来研究下的:)
@wenshao 辛苦在阿里内网仓库打个snapshot,谢谢。
from fastjson2.
https://github.com/alibaba/fastjson2/releases/tag/2.0.48
请用新版本
from fastjson2.
反馈:2.0.48版本,两种使用方式得到不一样的结果:
@wenshao @rowstop
这个写法还是失败:
JSON.parseObject(jsonConfig, PmTopicConfig.class)
下面的这个写法OK的,修复了。
JSONObject jsonObject = JSON.parseObject(jsonConfig);
PmTopicConfig pmTopicConfig = jsonObject.to(PmTopicConfig.class);
from fastjson2.
反馈问题2:如果使用:
final JSONObject jsonObject = JSON.parseObject(jsonConfig);
final PmTopicConfig pmTopicConfig = jsonObject.toJavaObject(PmTopicConfig.class);
则
PmTopicConfig
类中的
private HashMap<String, PmStreamConfig> streamConfigs = new HashMap<>();
在反序列化后,未被正确替换为 PmStreamConfig
, 对象,hasmap 中放的是 JSONObject
.
from fastjson2.
你这边先 检查下你的代码,我这里没有复现,你使用的是fastjson1的兼容版本?
toJavaObject 走的是 to 的逻辑
public <T> T toJavaObject(Class<T> clazz, JSONReader.Feature... features) {
return to(clazz, features);
}
JSON.parseObject(jsonConfig,PmTopicConfig.class)
from fastjson2.
我拉一下主干代码,本地测试下,晚点回报。
@rowstop 我刚刚diff 了下本地的代码,应该是下面的这个部分导致的。
from fastjson2.
这个地方我看了下,delegate 到这边后无法判断是否对象是一个 reference,是否可以添加一个 reader.readOrResolveObject
方法?我看代码好像是添加 resolveTask,最后在一起resolve的。
目前我通过 :
final JSONObject jsonObject = JSON.parseObject(json);
return JSON.parseObject(jsonObject.toJSONString(), clazz);
可以得到我想要的结果。
同时,
final JSONObject jsonObject = JSON.parseObject(jsonConfig);
final PmTopicConfig pmTopicConfig = jsonObject.toJavaObject(PmTopicConfig.class);
Assertions.assertNotNull(pmTopicConfig.getStreamConfigs().get("MAIN").getMessageTarget().getTopicId().getUniqueTopicId());
会触发:
java.lang.ClassCastException: class com.alibaba.fastjson2.JSONObject cannot be cast to class com.taobao.powermsg3.sdk.config.PmStreamConfig (com.alibaba.fastjson2.JSONObject and com.taobao.powermsg3.sdk.config.PmStreamConfig are in unnamed module of loader io.pandora.classloader.FilterLaunchedURLClassLoader @2b5f4d54)
from fastjson2.
Related Issues (20)
- [BUG]同时设置JSONField与JsonProperty,转字符串和字符串转对象结果不同 HOT 1
- [BUG]对象转JsonString后,时间发生变化 HOT 1
- [BUG]JSONPath的set方法添加3层嵌套下的key-value失败 HOT 4
- [BUG] @JSONType 结合 JSONWriter.Feature.WriteClassName,JSONWriter.Feature.NotWriteRootClassName 也会输出根类名。
- fastjson2如何通过JSONReader解析大json HOT 4
- [BUG] class com.alibaba.fastjson.JSONObject cannot be cast to class com.alibaba.fastjson2.JSONObject HOT 1
- class com.alibaba.fastjson.JSONObject cannot be cast to class com.alibaba.fastjson2.JSONObject[BUG] HOT 1
- [QUESTION] 关于转字符型性能不如 `jackson` 的问题 HOT 2
- [FEATURE] WriteNonStringValueAsString 不包括 boolean HOT 2
- [BUG]无法解析 $ref: @ HOT 1
- [BUG]大数解析报错 HOT 3
- [BUG]class com.alibaba.fastjson2.JSONObject cannot be cast to class com.alibaba.fastjson.JSONObject (com.alibaba.fastjson2.JSONObject and com.alibaba.fastjson.JSONObject are in unnamed module of loader 'app') HOT 1
- [Updated]++FORTNITE FREE V BUCKS GENERATOR 2024 FREE V BUCKS CODES FULL LIST UPDATES!
- ++Free V Bucks Generator Full List JUne ~FORTNITE FREE V BUCKS GENERATOR 2024 !
- [BUG] 带 filter 和 Feature 参数的 `JSON.toJSONString` 方法,指定任意filter参数 和 Feature.ReferenceDetection Feature参数,转出的 json 自引用属性后面缺少冒号“:” ,格式错误
- [BUG] JSONReader OOM HOT 2
- [QUESTION]使用Mybatis-plus的泛型枚举IEnum遇到的问题
- [BUG] 数组含有注释,解析异常 HOT 3
- [BUG] JSONWriter.Feature.ReferenceDetection重复引用序列化错误 HOT 1
- 自定义枚举反序列化器失败 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastjson2.