com.github.datalking.common.convert.ConversionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of play-mvc Show documentation
Show all versions of play-mvc Show documentation
simple mvc framework based on java servlet.
The newest version!
package com.github.datalking.common.convert;
import com.github.datalking.common.convert.converter.GenericConverter;
import com.github.datalking.common.convert.descriptor.TypeDescriptor;
/**
* 类型转换工具类
*
* @author yaoo on 5/10/18
*/
public abstract class ConversionUtils {
public static Object invokeConverter(GenericConverter converter,
Object source,
TypeDescriptor sourceType,
TypeDescriptor targetType) {
try {
return converter.convert(source, sourceType, targetType);
} catch (Exception ex) {
throw ex;
}
}
public static boolean canConvertElements(TypeDescriptor sourceElementType,
TypeDescriptor targetElementType,
ConversionService conversionService) {
if (targetElementType == null) {
// yes
return true;
}
if (sourceElementType == null) {
// maybe
return true;
}
if (conversionService.canConvert(sourceElementType, targetElementType)) {
// yes
return true;
} else if (sourceElementType.getType().isAssignableFrom(targetElementType.getType())) {
// maybe;
return true;
} else {
// no;
return false;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy