代码拉取完成,页面将自动刷新
org.springframework.core.convert.support.ConversionUtils
接下来我们详细查看一下方法
@Nullable
public static Object invokeConverter(GenericConverter converter, @Nullable Object source,
TypeDescriptor sourceType, TypeDescriptor targetType) {
try {
// converter 方法调用
return converter.convert(source, sourceType, targetType);
}
catch (ConversionFailedException ex) {
throw ex;
}
catch (Throwable ex) {
throw new ConversionFailedException(sourceType, targetType, source, ex);
}
}
public static boolean canConvertElements(@Nullable TypeDescriptor sourceElementType,
@Nullable TypeDescriptor targetElementType, ConversionService conversionService) {
if (targetElementType == null) {
// yes
return true;
}
if (sourceElementType == null) {
// maybe
return true;
}
if (conversionService.canConvert(sourceElementType, targetElementType)) {
// yes
return true;
}
// 右侧类型是否可以赋值给左侧类型
// 是否是父子类
if (ClassUtils.isAssignable(sourceElementType.getType(), targetElementType.getType())) {
// maybe
return true;
}
// no
return false;
}
public static Class<?> getEnumType(Class<?> targetType) {
Class<?> enumType = targetType;
while (enumType != null && !enumType.isEnum()) {
enumType = enumType.getSuperclass();
}
Assert.notNull(enumType, () -> "The target type " + targetType.getName() + " does not refer to an enum");
return enumType;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。