public static Object toValue ( String name , Object value ) { String [ ] parts = StringUtils . split ( name , "@" , 2 ) ; String fieldName = null ; String fieldType = "String" ; if ( parts . length == 2 ) { fieldType = parts [ 1 ] ; fieldName = parts [ 0 ] ; } else if ( parts . length == 1 ) { fieldName = parts [ 0 ] ; } else { throw new IllegalArgumentException ( "Invalid property name" ) ; } try { int l = Array . getLength ( value ) ; RequestParameterType < ? > rpt = TYPES . get ( fieldType ) ; if ( rpt == null ) { rpt = TYPES . get ( RequestParameterType . STRING ) ; } if ( ! fieldName . endsWith ( "[]" ) && l == 1 ) { return rpt . newInstance ( Array . get ( value , 0 ) ) ; } Class < ? > componentType = rpt . getComponentType ( ) ; Object [ ] a = ( Object [ ] ) Array . newInstance ( componentType , l ) ; for ( int i = 0 ; i < l ; i ++ ) { a [ i ] = rpt . newInstance ( Array . get ( value , i ) ) ; } return a ; } catch ( IllegalArgumentException e ) { RequestParameterType < ? > rpt = TYPES . get ( fieldType ) ; if ( rpt == null ) { rpt = TYPES . get ( RequestParameterType . STRING ) ; } return rpt . newInstance ( value ) ; } }
Creates the most suitable type .