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

[BUG] class java.util.HashSet cannot be cast to class java.util.List #2302

Closed
rongmome opened this issue Mar 8, 2024 · 2 comments
Closed
Labels
bug Something isn't working fixed
Milestone

Comments

@rongmome
Copy link

rongmome commented Mar 8, 2024

问题描述

Caused by: java.lang.ClassCastException: class java.util.HashSet cannot be cast to class java.util.List (java.util.HashSet and java.util.List are in module java.base of loader 'bootstrap')
at com.alibaba.fastjson2.reader.FieldReaderList.readFieldValue(FieldReaderList.java:100)
at com.alibaba.fastjson2.reader.ObjectReaderBean.readObject(ObjectReaderBean.java:390)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:515)

环境信息

  • OS信息:
  • JDK信息: jdk-21
com.alibaba fastjson 2.0.47

重现步骤

运行下面代码

import com.alibaba.fastjson.JSON;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;

public class Test {

    public static void main(String[] args) {
        TestA a = new TestA();
        a.areaIds.add(1000);
        String jsonStr = JSON.toJSONString(a);
        System.out.println(jsonStr); // {"areaIds":[1000]}
        JSON.parseObject(jsonStr, TestA.class);
    }

    public static class TestA {
        public Set<Integer> areaIds = new HashSet<>();
        transient public AtomicBoolean supplying = new AtomicBoolean(false);
    }
}
@wenshao
Copy link
Member

wenshao commented Mar 9, 2024

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.48-SNAPSHOT/
问题已修复,请帮忙用2.0.48-SNAPSHOT版本帮忙验证,2.0.48版本预计在3月底前发布。

@wenshao
Copy link
Member

wenshao commented Mar 25, 2024

@wenshao wenshao closed this as completed Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants