code: public static Collection toCollection( JSONArray jsonArray, JsonConfig jsonConfig ) {
        Collection collection = null;
        Class collectionType = jsonConfig.getCollectionType();
  
        if( collectionType.isInterface() ){
           if( collectionType.equals( List.class ) ){
              collection = new ArrayList();
           }else if( collectionType.equals( Set.class ) ){
              collection = new HashSet();
           }else{
              throw new JSONException( "unknown interface: " + collectionType );
           }
        }else{
           try{
              collection = (Collection) collectionType.newInstance();
           }catch( InstantiationException e ){
              throw new JSONException( e );
           }catch( IllegalAccessException e ){
              throw new JSONException( e );
           }
        }
  
        Class objectClass = jsonConfig.getRootClass();
        Map classMap = jsonConfig.getClassMap();
  
        int size = jsonArray.size();
        for( int i = 0; i < size; i++ ){
           Object value = jsonArray.get( i );
  
           if( JSONUtils.isNull( value ) ){
              collection.add( null );
           }else{
              Class type = value.getClass();
              if( JSONArray.class.isAssignableFrom( value.getClass() ) ){
                 collection.add( toCollection( (JSONArray) value, jsonConfig ) );
              }else if( String.class.isAssignableFrom( type )
                    || Boolean.class.isAssignableFrom( type ) || JSONUtils.isNumber( type )
                    || Character.class.isAssignableFrom( type )
                    || JSONFunction.class.isAssignableFrom( type ) ){
                 if( objectClass != null && !objectClass.isAssignableFrom( type ) ){
                    value = JSONUtils.getMorpherRegistry()
                       .morph( objectClass, value );
                 }
                 collection.add( value );
              }else{
                 if( objectClass != null ){
                    JsonConfig jsc = jsonConfig.copy();
                    jsc.setRootClass( objectClass );
                    jsc.setClassMap( classMap );
                    collection.add( JSONObject.toBean( (JSONObject) value, jsc ) );
                 }else{
                    collection.add( JSONObject.toBean( (JSONObject) value ) );
                 }
              }
           }
        }
  
        return collection;
     }
docs: Returns a List or a Set taking generics into account.<br/> Contributed by
  [Matt Small @ WaveMaker].