chinabugotech/hutool · error · ConvertException

Can not Converter from [{}] to [{}]

Error message

Can not Converter from [{}] to [{}]

What it means

ConverterRegistry.convert is the central dispatcher. After checking custom/standard converters, special-type conversion (Collection/Map/Array/Cast), and bean conversion, if nothing handled the value it throws ConvertException with source and target type names.

Source

Thrown at hutool-core/src/main/java/cn/hutool/core/convert/ConverterRegistry.java:248

			} else {
				// 无法识别的泛型类型,按照Object处理
				return (T) value;
			}
		}

		// 特殊类型转换,包括Collection、Map、强转、Array等
		final T result = convertSpecial(type, rowType, value, defaultValue);
		if (null != result) {
			return result;
		}

		// 尝试转Bean
		if (BeanUtil.isBean(rowType)) {
			return new BeanConverter<T>(type).convert(value, defaultValue);
		}

		// 无法转换
		throw new ConvertException("Can not Converter from [{}] to [{}]", value.getClass().getName(), type.getTypeName());
	}

	/**
	 * 转换值为指定类型<br>
	 * 自定义转换器优先
	 *
	 * @param <T>          转换的目标类型(转换器转换到的类型)
	 * @param type         类型
	 * @param value        值
	 * @param defaultValue 默认值
	 * @return 转换后的值
	 * @throws ConvertException 转换器不存在
	 */
	public <T> T convert(Type type, Object value, T defaultValue) throws ConvertException {
		return convert(type, value, defaultValue, true);
	}

	/**

View on GitHub (pinned to 8870454b2a)

Solutions

  1. Register a custom Converter for the target type via ConverterRegistry.getInstance().putCustom(type, converter).
  2. Convert to an intermediate concrete type (Map or existing bean) then map manually.
  3. If the target is meant to be a bean, ensure it has a public no-arg constructor and readable properties so isBean() returns true.
  4. Catch ConvertException and provide a fallback or default.

Example fix

// before - no converter for MyType
MyType r = Convert.convert(obj, MyType.class);

// after - register a converter
ConverterRegistry.getInstance().putCustom(MyType.class, new MyTypeConverter());
MyType r = Convert.convert(obj, MyType.class);
Defensive patterns

Strategy: fallback

Validate before calling

Class<?> rawType = TypeUtil.getClass(type);
if (rawType == null || (ConverterRegistry.getInstance().getConverter(type, true) == null
        && !BeanUtil.isBean(rawType))) {
    // register a custom converter or convert via intermediate Map first
    ConverterRegistry.getInstance().putCustom(rawType, new MyConverter());
}
return Convert.convert(value, type);

Try / catch

try {
    return Convert.convert(value, type);
} catch (ConvertException e) {
    if (e.getMessage().startsWith("Can not Converter from")) {
        return defaultValue; // or register converter and retry
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling Convert.convert(value, TargetType.class) where TargetType is not a registered convertible type, not a bean, and no special-case handler applies (e.g. interfaces, abstract classes, generic type variables, arrays of unsupported components).

Common situations: Targeting abstract/interface types; using TypeReference with unresolved generics; converting to a class with no public no-arg constructor that BeanUtil cannot treat as a bean.

Related errors


AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14). Data as JSON: /api/errors/82b16b14219ebbec. Report an issue: GitHub.