chinabugotech/hutool · error · ConvertException

Unsupported to map from [{}] of type: {}

Error message

Unsupported to map from [{}] of type: {}

What it means

EntryConverter.convertInternal accepts Map.Entry (via Pair), Map, CharSequence containing a separator (= / : / ,), or a readable Bean (beanToMap). Any other source type leaves map null and throws ConvertException naming value and its class.

Source

Thrown at hutool-core/src/main/java/cn/hutool/core/convert/impl/EntryConverter.java:67

	protected Map.Entry<?, ?> convertInternal(Object value) {
		Map map = null;
		if (value instanceof Pair) {
			final Pair pair = (Pair) value;
			map = MapUtil.of(pair.getKey(), pair.getValue());
		}else if (value instanceof Map) {
			map = (Map) value;
		} else if (value instanceof CharSequence) {
			final CharSequence str = (CharSequence) value;
			map = strToMap(str);
		} else if (BeanUtil.isReadableBean(value.getClass())) {
			map = BeanUtil.beanToMap(value);
		}

		if (null != map) {
			return mapToEntry(pairType, keyType, valueType, map);
		}

		throw new ConvertException("Unsupported to map from [{}] of type: {}", value, value.getClass().getName());
	}

	/**
	 * 字符串转单个键值对的Map,支持分隔符{@code :}、{@code =}、{@code ,}
	 *
	 * @param str 字符串
	 * @return map or null
	 */
	private static Map<CharSequence, CharSequence> strToMap(final CharSequence str) {
		// key:value  key=value  key,value
		final int index = StrUtil.indexOf(str, '=', 0, str.length());

		if (index > -1) {
			return MapUtil.of(str.subSequence(0, index + 1), str.subSequence(index, str.length()));
		}
		return null;
	}

View on GitHub (pinned to 8870454b2a)

Solutions

  1. Wrap the value into a single-entry Map or a Pair before converting.
  2. If the source is a String, format it as "key=value" so strToMap can parse it.
  3. Use a Map/Pair source that the converter can read directly.

Example fix

// before
Map.Entry e = Convert.convert(42, Map.Entry.class);

// after - structured source
Map<String,Object> src = Collections.singletonMap("value", 42);
Map.Entry e = Convert.convert(src, Map.Entry.class);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(value instanceof Map) && !(value instanceof Map.Entry) && !(value instanceof Pair)
        && !(value instanceof CharSequence) && !BeanUtil.isReadableBean(value.getClass())) {
    value = Collections.singletonMap("value", value);
}
Convert.convert(value, entryType);

Type guard

value instanceof Map || value instanceof Map.Entry || value instanceof Pair
        || (value instanceof CharSequence && ((CharSequence)value).toString().matches(".*[=:,].*"))
        || BeanUtil.isReadableBean(value.getClass())

Try / catch

try {
    return Convert.convert(value, entryType);
} catch (ConvertException e) {
    if (e.getMessage().startsWith("Unsupported to map from")) { /* wrap in a Map */ }
    else throw e;
}

Prevention

When it happens

Trigger: Converting a Number, primitive, enum, or unsupported object to a Map.Entry / AbstractMap.SimpleEntry via Convert.convert(value, Map.Entry.class) or a typed Entry generic.

Common situations: Generic conversion pipeline hitting a Map.Entry target with a scalar source; converting a single value that lacks key/value structure.

Related errors


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