@@ -3440,7 +3440,7 @@ public <T> T fromJson(Class<T> clazz) {
34403440 return obj ;
34413441 } catch (NoSuchMethodException e ) {
34423442 throw new JSONException ("No no-arg constructor for class: " + clazz .getName (), e );
3443- } catch (InstantiationException | IllegalAccessException | InvocationTargetException e ) {
3443+ } catch (Exception e ) {
34443444 throw new JSONException ("Failed to instantiate or set field for class: " + clazz .getName (), e );
34453445 }
34463446 }
@@ -3500,7 +3500,11 @@ else if (!rawType.isPrimitive() && !rawType.isEnum() && value instanceof JSONObj
35003500 */
35013501 private Map <?, ?> convertToMap (JSONObject jsonMap , Type keyType , Type valueType , Class <?> mapType ) throws JSONException {
35023502 try {
3503- InstanceCreator <?> creator = collectionMapping .getOrDefault (mapType , () -> new HashMap <>());
3503+ InstanceCreator <?> creator = collectionMapping .get (mapType ) != null ? collectionMapping .get (mapType ) : new InstanceCreator <Map >() {
3504+ public Map create () {
3505+ return new HashMap ();
3506+ }
3507+ };
35043508 @ SuppressWarnings ("unchecked" )
35053509 Map <Object , Object > createdMap = (Map <Object , Object >) creator .create ();
35063510
@@ -3522,12 +3526,13 @@ else if (!rawType.isPrimitive() && !rawType.isEnum() && value instanceof JSONObj
35223526 /**
35233527 * Converts a String to an Enum value.
35243528 */
3525- private <E extends Enum < E > > E stringToEnum (Class <?> enumClass , String value ) throws JSONException {
3529+ private <E > E stringToEnum (Class <?> enumClass , String value ) throws JSONException {
35263530 try {
35273531 @ SuppressWarnings ("unchecked" )
3528- Method valueOfMethod = enumClass .getMethod ("valueOf" , String .class );
3532+ Class <E > enumType = (Class <E >) enumClass ;
3533+ Method valueOfMethod = enumType .getMethod ("valueOf" , String .class );
35293534 return (E ) valueOfMethod .invoke (null , value );
3530- } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e ) {
3535+ } catch (Exception e ) {
35313536 throw new JSONException ("Failed to convert string to enum: " + value + " for " + enumClass .getName (), e );
35323537 }
35333538 }
@@ -3539,11 +3544,11 @@ private <E extends Enum<E>> E stringToEnum(Class<?> enumClass, String value) thr
35393544 @ SuppressWarnings ("unchecked" )
35403545 private <T > Collection <T > fromJsonArray (JSONArray jsonArray , Class <?> collectionType , Type elementType ) throws JSONException {
35413546 try {
3542- InstanceCreator <?> creator = collectionMapping .getOrDefault (collectionType , new InstanceCreator <List >() {
3547+ InstanceCreator <?> creator = collectionMapping .get (collectionType ) != null ? collectionMapping . get ( collectionType ) : new InstanceCreator <List >() {
35433548 public List create () {
35443549 return new ArrayList ();
35453550 }
3546- }) ;
3551+ };
35473552 Collection <T > collection = (Collection <T >) creator .create ();
35483553
35493554 for (int i = 0 ; i < jsonArray .length (); i ++) {
0 commit comments