Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于Page.records默认值的问题 #6263

Closed
Alleninggx opened this issue Jun 18, 2024 · 11 comments
Closed

关于Page.records默认值的问题 #6263

Alleninggx opened this issue Jun 18, 2024 · 11 comments

Comments

@Alleninggx
Copy link

image

这里的EmptyList对象虽然是可序列化的,但是是一个immutable列表。

image

所以在Dubbo夸服务传输时,使用fastjson2对Page对象反序列化,会用List.add方法来添加records元素,导致会抛出UnsupportedOperationException异常。

所以这里的records是否可以用一个非immutable列表作为默认值?

对于PageDTO,描述是作为夸服务使用的,但我不了解怎么解决这个问题,请指教。

@nieqiurong
Copy link
Contributor

虽然可以修改成普通的ArrayList,但这大概率也可以通过升级fastjson解决.

@Alleninggx
Copy link
Author

fastjson已经是最新版本了

@nieqiurong
Copy link
Contributor

image
测试看着没什么问题,你断点看下readJSONBObject方法里面的参数把.

@nieqiurong
Copy link
Contributor

不确定是不是些这样的问题.
alibaba/fastjson2#1835

@Alleninggx
Copy link
Author

看issue里描述是同一个问题,我看看fastjson2那边能不能解决吧

@nieqiurong
Copy link
Contributor

拿fastjson的代码验证了一下,只有存在属性为public的情况才能复现这个情况,不确定是否为同个情况,需要补充复现工程来看看.

@nieqiurong
Copy link
Contributor

你的响应模型是自定义的还是直接PageDto?

public class App {

    public static void main(String[] args) {
        Page<Person> page = new Page<>();
        List<Person> data = new ArrayList<>();
        data.add(null);
        data.add(new Person("abc"));
        data.add(null);
        // page.data = Collections.unmodifiableList(data);
        page.setData(data);
        byte[] bytes = JSONB.toBytes(page);
        Page page1 = JSONB.parseObject(bytes, Page.class);
        System.out.println(page1);

    }

    public static class Person {
        private String name;

        public Person() {
        }

        public Person(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

    }

    public static class Page<T> {

        // 属性为public下才会出问题.
        public List<T> data = Collections.emptyList();

        public void setData(List<T> items) {
            this.data = items;
        }

        public List<T> getData() {
            return data;
        }

    }

}

@Alleninggx
Copy link
Author

Alleninggx commented Jun 24, 2024

Mapper定义了这个,然后一路原样返返回(mapper->service->dubbo->另一个server)。

Mapper:
image
Dubbo:
image

在Dubbo序列化前,具体类型是Page。

@Alleninggx
Copy link
Author

@nieqiurong https://github.com/Alleninggx/MybatisPlus-test
这是复现工程
image

改一下redis地址,先启动provider,再启动customer

@nieqiurong
Copy link
Contributor

image
发现是开启了这个就有影响,具体还得看下fastjson源码了.

@nieqiurong
Copy link
Contributor

alibaba/fastjson2#2734

@rowstop rowstop mentioned this issue Jun 25, 2024
nieqiurong added a commit that referenced this issue Jul 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants