fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

[BUG] JSON.parseArray Syntax

Open Cooperzzy opened this issue 1 year ago • 1 comments

问题描述

{}为空json对象,JSON.parseObject正常。使用parseArray时,fastjson2抛出异常,而fastjson将其解析为[{}]

环境信息

  • OS信息: [MacOS 12.7.4 M1 Pro 16 GB]
  • JDK信息: [Openjdk 17.0.6]
  • 版本信息:[Fastjson 2.0.49]

重现步骤


import com.alibaba.fastjson2.JSON;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertNotNull;

public class Issue1459_54 {
    @Test
    public void testMutated() {
        String json = "{}";
        List<String> strings = JSON.parseArray(json, String.class);
        assertNotNull(strings);
    }

    @Test
    public void testMutatedfj() {
        String json = "{}";
        List<String> strings = com.alibaba.fastjson.JSON.parseArray(json, String.class);
        assertNotNull(strings);
    }
}

期待的正确结果

希望Fastjson 与Fastjson2 在解析上保持一致语法规范

相关日志输出

com.alibaba.fastjson2.JSONException: syntax error : {, offset 1, character {, line 1, column 1, fastjson-version 2.0.49 {}

at com.alibaba.fastjson2.JSONReader.readArray(JSONReader.java:2339)
at com.alibaba.fastjson2.JSON.parseArray(JSON.java:2658)
at Issue1459_54.testMutated(Issue1459_54.java:17)

Cooperzzy avatar May 07 '24 16:05 Cooperzzy

这个例子在2.0.50修复了,麻烦温少加上fixed label吧,感谢。

Cooperzzy avatar May 18 '24 11:05 Cooperzzy

已修复

Cooperzzy avatar Jun 30 '24 13:06 Cooperzzy