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] fastjson:2.0.27-SNAPSHOT版本调用JSON.toJSONString() 方法时,产生npe #1332

Closed
immaojiangle opened this issue Apr 7, 2023 · 2 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@immaojiangle
Copy link

问题描述

fastjson 2.0.27-SNAPSHOT版本调用JSON.toJSONString() 方法时,产生npe

环境信息

image

重现步骤

1、分别定义2个类(一点要是公共类)

@Data
public class Aa {
    private List<Bb> bList;
}

@Data
public class Bb {
    private List<LocalDateTime> dateTimes;
}

2、执行测试用例

 @Test
    public void t2(){
        Aa a =new Aa();
        List<Bb> bList = new ArrayList<>();
        Bb b1 = new Bb();
        bList.add(b1);
        Bb b2 = new Bb();
        bList.add(b2);
        List<LocalDateTime> dateTimes1 = new ArrayList<>();
        dateTimes1.add(LocalDateTime.now());
        dateTimes1.add(LocalDateTime.now());
        b1.setDateTimes(dateTimes1);


        List<LocalDateTime> dateTimes2 = new ArrayList<>();
        dateTimes2.add(LocalDateTime.now());
//        dateTimes2.add(LocalDateTime.now());
        b2.setDateTimes(dateTimes2);
        a.setBList(bList);
        Map<String, Object> map2 = ReflectUtils.buildObjectForMap(a);
        String json = JSON.toJSONString(map2);
        System.out.println(json);
    }

出现空指针异常
image

image

@immaojiangle immaojiangle added the bug Something isn't working label Apr 7, 2023
@wenshao wenshao added this to the 2.0.27 milestone Apr 7, 2023
@wenshao wenshao added the fixed label Apr 7, 2023
@wenshao
Copy link
Member

wenshao commented Apr 7, 2023

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.27-SNAPSHOT/
问题已修复,请帮忙用2.0.27-SNAPSHOT版本验证

@wenshao
Copy link
Member

wenshao commented Apr 8, 2023

https://github.com/alibaba/fastjson2/releases/tag/2.0.27
问题已修复,请用新版本

@wenshao wenshao closed this as completed Apr 8, 2023
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