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

JSON.parseArray(json, 类对象)无限死循环;[BUG] #383

Closed
liuccc1 opened this issue May 30, 2022 · 2 comments
Closed

JSON.parseArray(json, 类对象)无限死循环;[BUG] #383

liuccc1 opened this issue May 30, 2022 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@liuccc1
Copy link

liuccc1 commented May 30, 2022

问题描述

简要描述您碰到的问题。
json字符串:[{id:'1',name:'Dean',age:32,entryDate:'2016-06-29 22:23:00'},{id:'2',name:'Yang',age:31}]
java对象:

public class Employee {
    private String id;
    private String name;
    private Integer age;
    private String birthday;
    private Date entryDate;
}

执行List list = JSON.parseArray(json, Employee.class); 陷入无限死循环。应该是以前的fastjson1支持属性无双引号包裹,但是fastjson2里面json字符串的属性名无双引号用这种就会有上述问题。

环境信息

请填写以下信息:

  • 版本信息:[e.g.:Fastjson2 2.0.5]
@liuccc1 liuccc1 added the bug Something isn't working label May 30, 2022
@wenshao
Copy link
Member

wenshao commented May 30, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.6-SNAPSHOT/

问题已经修复,请用2.0.6-SNAPSHOT版本验证,2.0.6正式版预计6月5日前发布。需要显示使用 JSONReader.Feature.AllowUnQuotedFieldNames

String str = "[{id:'1',name:'Dean',age:32,entryDate:'2016-06-29 22:23:00'},{id:'2',name:'Yang',age:31}]";
{
    List<Employee> employees = JSON.parseArray(str, Employee.class, JSONReader.Feature.AllowUnQuotedFieldNames);
    assertEquals(2, employees.size());
}

byte[] utf8 = str.getBytes(StandardCharsets.UTF_8);
{
    List<Employee> employees = JSON.parseArray(utf8, Employee.class, JSONReader.Feature.AllowUnQuotedFieldNames);
    assertEquals(2, employees.size());
}
{
    List<Employee> employees = JSON.parseArray(utf8, 0, utf8.length, StandardCharsets.US_ASCII, Employee.class, JSONReader.Feature.AllowUnQuotedFieldNames);
    assertEquals(2, employees.size());
}

assertThrows(JSONException.class, () -> JSON.parseArray(str, Employee.class));
assertThrows(JSONException.class, () -> JSON.parseArray(utf8, Employee.class));
assertThrows(JSONException.class, () -> JSON.parseArray(utf8, 0, utf8.length, StandardCharsets.US_ASCII, Employee.class));

@wenshao wenshao added this to the 2.0.6 milestone May 30, 2022
@wenshao
Copy link
Member

wenshao commented Jun 4, 2022

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

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

No branches or pull requests

2 participants