Skip to content

Commit 1ca08a2

Browse files
author
{李彦慧}({026834})
committed
bugfix for json and json array
1 parent fbe9968 commit 1ca08a2

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/main/java/com/alibaba/fastjson/parser/deserializer/JavaBeanDeserializer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ public <T> T deserialzeArrayMapping(DefaultJSONParser parser, Type type, Object
169169

170170
@SuppressWarnings("unchecked")
171171
public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName, Object object) {
172+
if (type == JSON.class || type == JSONObject.class) {
173+
return (T) parser.parse();
174+
}
175+
172176
final JSONLexer lexer = parser.getLexer(); // xxx
173177

174178
if (lexer.token() == JSONToken.NULL) {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.alibaba.json.bvt.bug;
2+
3+
import junit.framework.TestCase;
4+
5+
import com.alibaba.fastjson.JSON;
6+
7+
public class Bug_for_json_array extends TestCase {
8+
9+
public void test_bug() throws Exception {
10+
String jsonStr = "{\"state\":0,\"data\":[{\"items\":[{\"tip\":\"\u5218\u82e5\u82f1\",\"url\":\"xiami:\\/\\/artist\\/1930\"},{\"tip\":\"\u5218\u5fb7\u534e\",\"url\":\"xiami:\\/\\/artist\\/648\"}],\"type\":\"artist\"},{\"items\":[{\"tip\":\"\u6f02\u6d0b\u8fc7\u6d77\u6765\u770b\u4f60 (Live) - \u5218\u660e\u6e58\",\"url\":\"xiami:\\/\\/song\\/1773431302\"},{\"tip\":\"\\u6211\\u4eec\\u6ca1\\u6709\\u5728\\u4e00\\u8d77 - \\u5218\\u82e5\\u82f1\",\"url\":\"xiami:\\/\\/song\\/1769471863\"},{\"tip\":\"\\u54ed\u7802 (Live)(\\u5218\\u660e\\u6e58\\u80dc\\u51fa) - \\u5218\u660e\u6e58\",\"url\":\"xiami:\\/\\/ song\\/1773484887\"}],\"type\":\"song\"},{\"items\":[{\"tip\":\"\\u4eb2\\u7231\\u7684\\u8def\\u4eba - \\u5218\\u82e5\\u82f1\",\"url\":\"xiami:\\/\\/album\\/55230\"},{\"tip\":\"\\u5728\\u4e00\\u8d77 - \\u5218\\u82e5\\u82f1\",\"url\":\"xiami:\\/\\/album\\/377241\"}],\"type\":\"album\"}],\"status\":\"ok\",\"err\":null} ";
11+
12+
Parser parser = JSON.parseObject(jsonStr, Parser.class);
13+
14+
System.out.println(JSON.toJSONString(parser));
15+
}
16+
17+
public static class Parser {
18+
19+
public int state;
20+
public JSON data;
21+
public String status;
22+
public String err;
23+
24+
public int getState() {
25+
return state;
26+
}
27+
28+
public void setState(int state) {
29+
this.state = state;
30+
}
31+
32+
public JSON getData() {
33+
return data;
34+
}
35+
36+
public void setData(JSON data) {
37+
this.data = data;
38+
}
39+
40+
public String getStatus() {
41+
return status;
42+
}
43+
44+
public void setStatus(String status) {
45+
this.status = status;
46+
}
47+
48+
public String getErr() {
49+
return err;
50+
}
51+
52+
public void setErr(String err) {
53+
this.err = err;
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)