public static Object convert ( Type type , String value ) { if ( null == value ) { return value ; } if ( "" . equals ( value ) ) { if ( type . equals ( String . class ) ) { return value ; } if ( type . equals ( int . class ) || type . equals ( double . class ) || type . equals ( short . class ) || type . equals ( long . class ) || type . equals ( byte . class ) || type . equals ( float . class ) ) { return 0 ; } if ( type . equals ( boolean . class ) ) { return false ; } return null ; } if ( type . equals ( int . class ) || type . equals ( Integer . class ) ) { return Integer . parseInt ( value ) ; } else if ( type . equals ( String . class ) ) { return value ; } else if ( type . equals ( Double . class ) || type . equals ( double . class ) ) { return Double . parseDouble ( value ) ; } else if ( type . equals ( Float . class ) || type . equals ( float . class ) ) { return Float . parseFloat ( value ) ; } else if ( type . equals ( Long . class ) || type . equals ( long . class ) ) { return Long . parseLong ( value ) ; } else if ( type . equals ( Boolean . class ) || type . equals ( boolean . class ) ) { return Boolean . parseBoolean ( value ) ; } else if ( type . equals ( Short . class ) || type . equals ( short . class ) ) { return Short . parseShort ( value ) ; } else if ( type . equals ( Byte . class ) || type . equals ( byte . class ) ) { return Byte . parseByte ( value ) ; } else if ( type . equals ( BigDecimal . class ) ) { return new BigDecimal ( value ) ; } else if ( type . equals ( Date . class ) ) { if ( value . length ( ) == 10 ) return DateKit . toDate ( value , "yyyy-MM-dd" ) ; return DateKit . toDateTime ( value , "yyyy-MM-dd HH:mm:ss" ) ; } else if ( type . equals ( LocalDate . class ) ) { return DateKit . toLocalDate ( value , "yyyy-MM-dd" ) ; } else if ( type . equals ( LocalDateTime . class ) ) { return DateKit . toLocalDateTime ( value , "yyyy-MM-dd HH:mm:ss" ) ; } return value ; }
Converts a string type to a target type