private Object instantiate ( Class actualType , JSONObject j ) { Object r = bindInterceptor . instantiate ( actualType , j ) ; if ( r != BindInterceptor . DEFAULT ) return r ; for ( BindInterceptor bi : getWebApp ( ) . bindInterceptors ) { r = bi . instantiate ( actualType , j ) ; if ( r != BindInterceptor . DEFAULT ) return r ; } if ( actualType == JSONObject . class || actualType == JSON . class ) return actualType . cast ( j ) ; String [ ] names = new ClassDescriptor ( actualType ) . loadConstructorParamNames ( ) ; // the actual arguments to invoke the constructor with. Object [ ] args = new Object [ names . length ] ; // constructor Constructor c = findConstructor ( actualType , names . length ) ; Class [ ] types = c . getParameterTypes ( ) ; Type [ ] genTypes = c . getGenericParameterTypes ( ) ; // convert parameters for ( int i = 0 ; i < names . length ; i ++ ) { try { args [ i ] = bindJSON ( genTypes [ i ] , types [ i ] , j . get ( names [ i ] ) ) ; } catch ( IllegalArgumentException e ) { throw new IllegalArgumentException ( "Failed to convert the " + names [ i ] + " parameter of the constructor " + c , e ) ; } } Object o = injectSetters ( invokeConstructor ( c , args ) , j , Arrays . asList ( names ) ) ; o = bindResolve ( o , j ) ; return o ; }
Called after the actual type of the binding is figured out .