Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

fix issue 2638[解析非法字符串JSON.parseObject("}",JaveBean.class ) 没有抛出异常,测试"] " 可以抛出] #2641

Merged
merged 2 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@ public <T> T parseObject(Type type, Object fieldName) {

try {
if (deserializer.getClass() == JavaBeanDeserializer.class) {
if (lexer.token()!= JSONToken.LBRACE && lexer.token()!=JSONToken.LBRACKET) {
throw new JSONException("syntax error,except start with { or [,but actually start with "+ lexer.tokenName());
}
return (T) ((JavaBeanDeserializer) deserializer).deserialze(this, type, fieldName, 0);
} else {
return (T) deserializer.deserialze(this, type, fieldName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.alibaba.fastjson.deserializer.issue2638;

class Person {
private String name;
private Integer age;

public Person(){}

public Person(String name, Integer age) {
super();
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.alibaba.fastjson.deserializer.issue2638;

import com.alibaba.fastjson.JSON;
import org.junit.Test;

/**
* @Author:JacceYang chaoyang_sjtu@126.com
* @Description:
* @Data:Initialized in 7:54 PM 2019/8/17
**/
public class TestIssue2638 {

@Test
public void testBug2638() {
String str="}";
JSON.parseObject(str,Person.class);
}
}