Skip to content

Commit be00ec4

Browse files
committed
fix field order
1 parent 641d940 commit be00ec4

File tree

2 files changed

+6
-35
lines changed

2 files changed

+6
-35
lines changed

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

Lines changed: 5 additions & 34 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,12 +64,10 @@ public static String getCorrectJson(String s, boolean isArray) {
6464
* @param json
6565
* @return
6666
*/
67-
private static final Feature[] DEFAULT_FASTJSON_FEATURES = {Feature.OrderedField, Feature.AllowSingleQuotes, Feature.UseBigDecimal, Feature.UseObjectArray};
67+
private static final JSONReader.Feature[] DEFAULT_FASTJSON_FEATURES = {JSONReader.Feature.FieldBased, JSONReader.Feature.UseBigDecimalForDoubles};
6868
public static Object parse(Object obj) {
69-
int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE;
70-
features |= Feature.OrderedField.getMask();
7169
try {
72-
return com.alibaba.fastjson.JSON.parse(obj instanceof String ? (String) obj : toJSONString(obj), DEFAULT_FASTJSON_FEATURES);
70+
return com.alibaba.fastjson2.JSON.parse(obj instanceof String ? (String) obj : toJSONString(obj), DEFAULT_FASTJSON_FEATURES);
7371
} catch (Exception e) {
7472
Log.i(TAG, "parse catch \n" + e.getMessage());
7573
}
@@ -91,32 +89,7 @@ public static JSONObject parseObject(Object obj) {
9189
* @return
9290
*/
9391
public static JSONObject parseObject(String json) {
94-
return parseObject(json, DEFAULT_FASTJSON_FEATURES);
95-
}
96-
97-
/**
98-
* json转JSONObject
99-
*
100-
* @param json
101-
* @param features
102-
* @return
103-
*/
104-
public static JSONObject parseObject(String json, Feature... features) {
105-
try {
106-
return com.alibaba.fastjson.JSON.parseObject(getCorrectJson(json), JSONObject.class, features);
107-
} catch (Exception e) {
108-
Log.i(TAG, "parseObject catch \n" + e.getMessage());
109-
}
110-
return null;
111-
}
112-
113-
/**JSONObject转实体类
114-
* @param object
115-
* @param clazz
116-
* @return
117-
*/
118-
public static <T> T parseObject(JSONObject object, Class<T> clazz) {
119-
return parseObject(toJSONString(object), clazz);
92+
return parseObject(json, JSONObject.class);
12093
}
12194
/**json转实体类
12295
* @param json
@@ -128,9 +101,7 @@ public static <T> T parseObject(String json, Class<T> clazz) {
128101
Log.e(TAG, "parseObject clazz == null >> return null;");
129102
} else {
130103
try {
131-
int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE;
132-
features |= Feature.OrderedField.getMask();
133-
return com.alibaba.fastjson.JSON.parseObject(getCorrectJson(json), clazz, DEFAULT_FASTJSON_FEATURES);
104+
return com.alibaba.fastjson2.JSON.parseObject(getCorrectJson(json), clazz, DEFAULT_FASTJSON_FEATURES);
134105
} catch (Exception e) {
135106
Log.i(TAG, "parseObject catch \n" + e.getMessage());
136107
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ else if (value instanceof String) { // //key{}@ getRealKey, 引用赋值路径
425425
String replaceKey = key.substring(0, key.length() - 1);
426426

427427
// System.out.println("getObject key.endsWith(@) >> parseRelation = " + parseRelation);
428-
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);
429429

430430
//先尝试获取,尽量保留缺省依赖路径,这样就不需要担心路径改变
431431
Object target = onReferenceParse(targetPath);

0 commit comments

Comments
 (0)