66import com .fasterxml .jackson .core .json .JsonReadFeature ;
77import com .fasterxml .jackson .databind .DeserializationFeature ;
88import com .fasterxml .jackson .databind .JsonNode ;
9- import com .fasterxml .jackson .databind .MapperFeature ;
109import com .fasterxml .jackson .databind .ObjectMapper ;
1110import com .fasterxml .jackson .databind .SerializationFeature ;
1211import com .fasterxml .jackson .databind .json .JsonMapper ;
@@ -41,22 +40,27 @@ public final class JSON {
4140 .enable (JsonReadFeature .ALLOW_UNQUOTED_FIELD_NAMES )
4241 // Fastjson Feature.AllowSingleQuotes (default ON)
4342 .enable (JsonReadFeature .ALLOW_SINGLE_QUOTES )
44- // Fastjson tolerates trailing commas (e.g. {"a":1,}) by default
43+ // Partial compatibility with Fastjson Feature.AllowArbitraryCommas:
44+ // this only covers a single trailing comma like {"a":1,} or [1,2,].
45+ // Fastjson also accepts repeated/arbitrary commas like {"a":1,,,,} and
46+ // [1,,2], which Jackson does not support with this feature.
4547 .enable (JsonReadFeature .ALLOW_TRAILING_COMMA )
46- // Fastjson accepts NaN as valid tokens, Infinity is invalid
48+ // Fastjson accepts NaN as null but rejects Infinity by default.
49+ // Jackson enables both with this feature, so every parse path must normalize
50+ // NaN and reject +/-Infinity after reading.
4751 .enable (JsonReadFeature .ALLOW_NON_NUMERIC_NUMBERS )
48- // Fastjson accepts leading plus sign for numbers (e.g. +123)
52+ // Fastjson accepts a leading plus sign for numbers (for example +123, +0.5 )
4953 .enable (JsonReadFeature .ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS )
50- // Fastjson accepts leading decimal point for numbers (e.g. .5)
54+ // Partial compatibility for Fastjson's asymmetric decimal behavior:
55+ // Fastjson accepts +.5 but rejects .5 by default. Jackson cannot model only
56+ // the signed form, so enabling this also accepts .5.
5157 .enable (JsonReadFeature .ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS )
52- // Fastjson accepts trailing decimal point for numbers (e.g. 5.)
58+ // Fastjson accepts a trailing decimal point for numbers (for example 5.)
5359 .enable (JsonReadFeature .ALLOW_TRAILING_DECIMAL_POINT_FOR_NUMBERS )
54- // Fastjson accepts leading zeros for numbers (e.g. 007)
60+ // Fastjson accepts leading zeros for numbers (for example 007)
5561 .enable (JsonReadFeature .ALLOW_LEADING_ZEROS_FOR_NUMBERS )
56- // Fastjson accepts unescaped control chars in strings (e.g. raw tab/newline)
62+ // Fastjson accepts unescaped control chars in strings (for example raw tab/newline)
5763 .enable (JsonReadFeature .ALLOW_UNESCAPED_CONTROL_CHARS )
58- // Fastjson accepts backslash-escaping any character (e.g. \q -> q)
59- .enable (JsonReadFeature .ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER )
6064 // Fastjson accepts Java-style comments (// and /* */)
6165 .enable (JsonReadFeature .ALLOW_JAVA_COMMENTS )
6266 // Fastjson Feature.UseBigDecimal (default ON)
@@ -69,11 +73,6 @@ public final class JSON {
6973 // Fastjson omits null-valued fields by default (WriteMapNullValue is OFF by default)
7074 // https://github.com/alibaba/fastjson/wiki/WriteNull_cn
7175 .serializationInclusion (JsonInclude .Include .NON_NULL )
72- // Fastjson uses WriteDateUseDateFormat (string) not timestamps by default
73- .disable (SerializationFeature .WRITE_DATES_AS_TIMESTAMPS )
74- // Fastjson smart-match: field names are matched ignoring case/underscores by default
75- // (DisableFieldSmartMatch is OFF by default -> smart match ON)
76- .configure (MapperFeature .ACCEPT_CASE_INSENSITIVE_PROPERTIES , true )
7776 .build ();
7877
7978 private static JsonFactory buildFactory () {
@@ -230,23 +229,6 @@ public static JSONObject parseObject(String text) {
230229 }
231230 }
232231
233- public static <T > T parseObject (String text , Class <T > clazz ) {
234- if (isNullLiteral (text )) {
235- return null ;
236- }
237- if (clazz == JSONObject .class ) {
238- return clazz .cast (parseObject (text ));
239- }
240- if (clazz == JSONArray .class ) {
241- return clazz .cast (parseArray (text ));
242- }
243- try {
244- return MAPPER .readValue (text , clazz );
245- } catch (Exception e ) {
246- throw new JSONException (e .getMessage (), e );
247- }
248- }
249-
250232 public static JsonNode parse (String text ) {
251233 if (isNullLiteral (text )) {
252234 return null ;
0 commit comments