6
6
7
7
import com .alibaba .fastjson .JSONArray ;
8
8
import com .alibaba .fastjson .JSONObject ;
9
- import com .alibaba .fastjson .parser .Feature ;
10
9
import com .alibaba .fastjson .serializer .SerializerFeature ;
10
+ import com .alibaba .fastjson2 .JSONReader ;
11
11
12
12
import java .util .List ;
13
13
@@ -64,12 +64,10 @@ public static String getCorrectJson(String s, boolean isArray) {
64
64
* @param json
65
65
* @return
66
66
*/
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 };
68
68
public static Object parse (Object obj ) {
69
- int features = com .alibaba .fastjson .JSON .DEFAULT_PARSER_FEATURE ;
70
- features |= Feature .OrderedField .getMask ();
71
69
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 );
73
71
} catch (Exception e ) {
74
72
Log .i (TAG , "parse catch \n " + e .getMessage ());
75
73
}
@@ -91,32 +89,7 @@ public static JSONObject parseObject(Object obj) {
91
89
* @return
92
90
*/
93
91
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 );
120
93
}
121
94
/**json转实体类
122
95
* @param json
@@ -128,9 +101,7 @@ public static <T> T parseObject(String json, Class<T> clazz) {
128
101
Log .e (TAG , "parseObject clazz == null >> return null;" );
129
102
} else {
130
103
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 );
134
105
} catch (Exception e ) {
135
106
Log .i (TAG , "parseObject catch \n " + e .getMessage ());
136
107
}
0 commit comments