Skip to content

Commit c041000

Browse files
authored
Merge pull request Tencent#401 from NeoGitCrt1/fastjson2
Fastjson2
2 parents 8329421 + be00ec4 commit c041000

File tree

3 files changed

+29
-57
lines changed

3 files changed

+29
-57
lines changed

APIJSONORM/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>apijson.orm</groupId>
77
<artifactId>apijson-orm</artifactId>
8-
<version>5.1.0</version>
8+
<version>5.1.0-F2</version>
99
<packaging>jar</packaging>
1010

1111
<name>APIJSONORM</name>
@@ -21,7 +21,7 @@
2121
<dependency>
2222
<groupId>com.alibaba</groupId>
2323
<artifactId>fastjson</artifactId>
24-
<version>1.2.79</version>
24+
<version>2.0.4</version>
2525
</dependency>
2626
<dependency>
2727
<groupId>javax.activation</groupId>

APIJSONORM/src/main/java/apijson/JSON.java

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
import com.alibaba.fastjson.JSONArray;
88
import com.alibaba.fastjson.JSONObject;
9-
import com.alibaba.fastjson.parser.Feature;
109
import com.alibaba.fastjson.serializer.SerializerFeature;
10+
import com.alibaba.fastjson2.JSONReader;
1111

1212
import java.util.List;
1313

@@ -64,18 +64,18 @@ public static String getCorrectJson(String s, boolean isArray) {
6464
* @param json
6565
* @return
6666
*/
67+
private static final JSONReader.Feature[] DEFAULT_FASTJSON_FEATURES = {JSONReader.Feature.FieldBased, JSONReader.Feature.UseBigDecimalForDoubles};
6768
public static Object parse(Object obj) {
68-
int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE;
69-
features |= Feature.OrderedField.getMask();
7069
try {
71-
return com.alibaba.fastjson.JSON.parse(obj instanceof String ? (String) obj : toJSONString(obj), features);
70+
return com.alibaba.fastjson2.JSON.parse(obj instanceof String ? (String) obj : toJSONString(obj), DEFAULT_FASTJSON_FEATURES);
7271
} catch (Exception e) {
7372
Log.i(TAG, "parse catch \n" + e.getMessage());
7473
}
7574
return null;
7675
}
76+
7777
/**obj转JSONObject
78-
* @param json
78+
* @param obj
7979
* @return
8080
*/
8181
public static JSONObject parseObject(Object obj) {
@@ -89,31 +89,7 @@ public static JSONObject parseObject(Object obj) {
8989
* @return
9090
*/
9191
public static JSONObject parseObject(String json) {
92-
int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE;
93-
features |= Feature.OrderedField.getMask();
94-
return parseObject(json, features);
95-
}
96-
/**json转JSONObject
97-
* @param json
98-
* @param features
99-
* @return
100-
*/
101-
public static JSONObject parseObject(String json, int features) {
102-
try {
103-
return com.alibaba.fastjson.JSON.parseObject(getCorrectJson(json), JSONObject.class, features);
104-
} catch (Exception e) {
105-
Log.i(TAG, "parseObject catch \n" + e.getMessage());
106-
}
107-
return null;
108-
}
109-
110-
/**JSONObject转实体类
111-
* @param object
112-
* @param clazz
113-
* @return
114-
*/
115-
public static <T> T parseObject(JSONObject object, Class<T> clazz) {
116-
return parseObject(toJSONString(object), clazz);
92+
return parseObject(json, JSONObject.class);
11793
}
11894
/**json转实体类
11995
* @param json
@@ -125,9 +101,7 @@ public static <T> T parseObject(String json, Class<T> clazz) {
125101
Log.e(TAG, "parseObject clazz == null >> return null;");
126102
} else {
127103
try {
128-
int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE;
129-
features |= Feature.OrderedField.getMask();
130-
return com.alibaba.fastjson.JSON.parseObject(getCorrectJson(json), clazz, features);
104+
return com.alibaba.fastjson2.JSON.parseObject(getCorrectJson(json), clazz, DEFAULT_FASTJSON_FEATURES);
131105
} catch (Exception e) {
132106
Log.i(TAG, "parseObject catch \n" + e.getMessage());
133107
}

APIJSONORM/src/main/java/apijson/orm/AbstractObjectParser.java

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55

66
package apijson.orm;
77

8-
import static apijson.JSONObject.KEY_COMBINE;
9-
import static apijson.JSONObject.KEY_DROP;
10-
import static apijson.JSONObject.KEY_TRY;
11-
import static apijson.RequestMethod.POST;
12-
import static apijson.RequestMethod.PUT;
13-
import static apijson.orm.SQLConfig.TYPE_ITEM;
8+
import apijson.JSONResponse;
9+
import apijson.Log;
10+
import apijson.NotNull;
11+
import apijson.RequestMethod;
12+
import apijson.StringUtil;
13+
import apijson.orm.AbstractFunctionParser.FunctionBean;
14+
import apijson.orm.exception.ConflictException;
15+
import apijson.orm.exception.NotExistException;
16+
import com.alibaba.fastjson.JSON;
17+
import com.alibaba.fastjson.JSONArray;
18+
import com.alibaba.fastjson.JSONObject;
1419

20+
import javax.activation.UnsupportedDataTypeException;
1521
import java.rmi.ServerException;
1622
import java.util.ArrayList;
1723
import java.util.Arrays;
@@ -22,20 +28,12 @@
2228
import java.util.Map.Entry;
2329
import java.util.Set;
2430

25-
import javax.activation.UnsupportedDataTypeException;
26-
27-
import com.alibaba.fastjson.JSON;
28-
import com.alibaba.fastjson.JSONArray;
29-
import com.alibaba.fastjson.JSONObject;
30-
31-
import apijson.JSONResponse;
32-
import apijson.Log;
33-
import apijson.NotNull;
34-
import apijson.RequestMethod;
35-
import apijson.StringUtil;
36-
import apijson.orm.AbstractFunctionParser.FunctionBean;
37-
import apijson.orm.exception.ConflictException;
38-
import apijson.orm.exception.NotExistException;
31+
import static apijson.JSONObject.KEY_COMBINE;
32+
import static apijson.JSONObject.KEY_DROP;
33+
import static apijson.JSONObject.KEY_TRY;
34+
import static apijson.RequestMethod.POST;
35+
import static apijson.RequestMethod.PUT;
36+
import static apijson.orm.SQLConfig.TYPE_ITEM;
3937

4038

4139
/**简化Parser,getObject和getArray(getArrayConfig)都能用
@@ -427,7 +425,7 @@ else if (value instanceof String) { // //key{}@ getRealKey, 引用赋值路径
427425
String replaceKey = key.substring(0, key.length() - 1);
428426

429427
// System.out.println("getObject key.endsWith(@) >> parseRelation = " + parseRelation);
430-
String targetPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, new String((String) value));
428+
String targetPath = AbstractParser.getValuePath(type == TYPE_ITEM ? path : parentPath, (String) value);
431429

432430
//先尝试获取,尽量保留缺省依赖路径,这样就不需要担心路径改变
433431
Object target = onReferenceParse(targetPath);
@@ -572,7 +570,7 @@ public JSON onChildParse(int index, String key, JSONObject value) throws Excepti
572570
invalidate();
573571
}
574572
}
575-
Log.i(TAG, "onChildParse ObjectParser.onParse key = " + key + "; child = " + child);
573+
// Log.i(TAG, "onChildParse ObjectParser.onParse key = " + key + "; child = " + child);
576574

577575
return isEmpty ? null : child;//只添加! isChildEmpty的值,可能数据库返回数据不够count
578576
}

0 commit comments

Comments
 (0)