@ SuppressWarnings ( "unchecked" ) public static < T > T stringToObject ( String value , Class < T > type ) { if ( value == null ) { return null ; } if ( type == String . class ) { return ( T ) value ; } else if ( type == String [ ] . class ) { return ( T ) decodeString ( splitPreserveAllTokens ( value , ARRAY_DELIMITER_CHAR ) ) ; } if ( type == Integer . class ) { return ( T ) ( Integer ) NumberUtils . toInt ( value , 0 ) ; } if ( type == Long . class ) { return ( T ) ( Long ) NumberUtils . toLong ( value , 0L ) ; } if ( type == Double . class ) { return ( T ) ( Double ) NumberUtils . toDouble ( value , 0d ) ; } if ( type == Boolean . class ) { return ( T ) ( Boolean ) BooleanUtils . toBoolean ( value ) ; } if ( type == Map . class ) { String [ ] rows = splitPreserveAllTokens ( value , ARRAY_DELIMITER_CHAR ) ; Map < String , String > map = new LinkedHashMap <> ( ) ; for ( int i = 0 ; i < rows . length ; i ++ ) { String [ ] keyValue = splitPreserveAllTokens ( rows [ i ] , KEY_VALUE_DELIMITER_CHAR ) ; if ( keyValue . length == 2 && StringUtils . isNotEmpty ( keyValue [ 0 ] ) ) { map . put ( decodeString ( keyValue [ 0 ] ) , StringUtils . isEmpty ( keyValue [ 1 ] ) ? null : decodeString ( keyValue [ 1 ] ) ) ; } } return ( T ) map ; } throw new IllegalArgumentException ( "Unsupported type: " + type . getName ( ) ) ; }
Converts a string value to an object with the given parameter type .