@Override public T convert(String sourceValue) throws ConversionException { if (StringUtil.isEmpty(sourceValue)) return null; else return super.convert(sourceValue); }
private Converter tryToCreateFactoryConverter(Class sourceType, Class targetType) { { // find instance method <targetType>Value() in source type String methodName = StringUtil.uncapitalize(targetType.getSimpleName()) + "Value"; Method typeValueMethod = BeanUtil.findMethod(sourceType, methodName, new Class[0]); if (typeValueMethod != null && (typeValueMethod.getModifiers() & Modifier.STATIC) == 0) return new SourceClassMethodInvoker(sourceType, targetType, typeValueMethod); } { // find static getInstance() method in target type Method getInstanceMethod = BeanUtil.findMethod(targetType, "getInstance", sourceType); if (getInstanceMethod != null && (getInstanceMethod.getModifiers() & Modifier.STATIC) == Modifier.STATIC) return new StaticTargetClassMethodInvoker(sourceType, targetType, getInstanceMethod); } { // find static valueOf() method in target type Method valueOfMethod = BeanUtil.findMethod(targetType, "valueOf", sourceType); if (valueOfMethod != null && (valueOfMethod.getModifiers() & Modifier.STATIC) == Modifier.STATIC) return new StaticTargetClassMethodInvoker(sourceType, targetType, valueOfMethod); } { // find target type constructor which takes source type argument Constructor constructor = BeanUtil.findConstructor(targetType, sourceType); if (constructor != null) return new ConstructorInvoker(sourceType, constructor); } return findPoorConfiguredMatch(sourceType, targetType); }