66
77import com .alibaba .fastjson .JSONArray ;
88import com .alibaba .fastjson .JSONObject ;
9- import com .alibaba .fastjson .parser .Feature ;
109import com .alibaba .fastjson .serializer .SerializerFeature ;
10+ import com .alibaba .fastjson2 .JSONReader ;
1111
1212import 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 }
0 commit comments