Skip to content

Commit a3661fc

Browse files
committed
bug fixed for List/Array parse support empty string. for issue alibaba#1150
1 parent 0f7dc97 commit a3661fc

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/main/java/com/alibaba/fastjson/parser/ListTypeFieldDeserializer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public ListTypeFieldDeserializer(ParserConfig mapping, Class<?> clazz, FieldInfo
3737
@SuppressWarnings({ "rawtypes", "unchecked" })
3838
@Override
3939
public void parseField(DefaultJSONParser parser, Object object, Type objectType, Map<String, Object> fieldValues) {
40-
if (parser.lexer.token == JSONToken.NULL) {
40+
JSONLexer lexer = parser.lexer;
41+
final int token = lexer.token();
42+
if (token == JSONToken.NULL
43+
|| (token == JSONToken.LITERAL_STRING && lexer.stringVal().length() == 0)) {
4144
setValue(object, null);
4245
parser.lexer.nextToken();
4346
return;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.alibaba.json.bvt.issue_1100;
2+
3+
import com.alibaba.fastjson.JSON;
4+
import junit.framework.TestCase;
5+
6+
import java.util.List;
7+
8+
/**
9+
* Created by wenshao on 24/04/2017.
10+
*/
11+
public class Issue1150 extends TestCase {
12+
public void test_for_issue() throws Exception {
13+
Model model = JSON.parseObject("{\"values\":\"\"}", Model.class);
14+
assertNull(model.values);
15+
}
16+
17+
public void test_for_issue_array() throws Exception {
18+
Model2 model = JSON.parseObject("{\"values\":\"\"}", Model2.class);
19+
assertNull(model.values);
20+
}
21+
22+
public static class Model {
23+
public List values;
24+
}
25+
26+
public static class Model2 {
27+
public Item[] values;
28+
}
29+
30+
public static class Item {
31+
32+
}
33+
}

0 commit comments

Comments
 (0)