Git Product home page Git Product logo

Comments (9)

rowstop avatar rowstop commented on June 12, 2024

这个方法的代码能看下吗?
CommonUtil.parseObject(jsonConfig, PmTopicConfig.class);
是否是类似于这个逻辑

        JSONObject jsonObject = JSON.parseObject(jsonConfig);
        PmTopicConfig pmTopicConfig = jsonObject.to(PmTopicConfig.class);

如果是下面这个逻辑应该没问题的

        JSON.parseObject(jsonConfig, PmTopicConfig.class)

from fastjson2.

wenshao avatar wenshao commented on June 12, 2024

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.

He-Pin avatar He-Pin commented on June 12, 2024

@wenshao @rowstop 感谢,我看了下单元测试很全面。本来说周末来研究下的:)

@wenshao 辛苦在阿里内网仓库打个snapshot,谢谢。

from fastjson2.

wenshao avatar wenshao commented on June 12, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.48
请用新版本

from fastjson2.

He-Pin avatar He-Pin commented on June 12, 2024

反馈:2.0.48版本,两种使用方式得到不一样的结果:
@wenshao @rowstop
这个写法还是失败:

JSON.parseObject(jsonConfig, PmTopicConfig.class)

返回:
image

下面的这个写法OK的,修复了。

JSONObject jsonObject = JSON.parseObject(jsonConfig);
PmTopicConfig pmTopicConfig = jsonObject.to(PmTopicConfig.class);

image

from fastjson2.

He-Pin avatar He-Pin commented on June 12, 2024

反馈问题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.

rowstop avatar rowstop commented on June 12, 2024

你这边先 检查下你的代码,我这里没有复现,你使用的是fastjson1的兼容版本?
toJavaObject 走的是 to 的逻辑

   public <T> T toJavaObject(Class<T> clazz, JSONReader.Feature... features) {
        return to(clazz, features);
    }

JSON.parseObject(jsonConfig,PmTopicConfig.class)
image

from fastjson2.

He-Pin avatar He-Pin commented on June 12, 2024

我拉一下主干代码,本地测试下,晚点回报。

@rowstop 我刚刚diff 了下本地的代码,应该是下面的这个部分导致的。

image

from fastjson2.

He-Pin avatar He-Pin commented on June 12, 2024

image
这个地方我看了下,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());

image

image

会触发:

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.