{"record":{"id":"0a79d8724c21df4e","repo":"chinabugotech/hutool","slug":"unsupported-source-type","errorCode":null,"errorMessage":"Unsupported source type: {}","messagePattern":"Unsupported source type: (.+?)","errorType":"exception","errorClass":"ConvertException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/convert/impl/BeanConverter.java","lineNumber":98,"sourceCode":"\t\tif(value instanceof Map ||\n\t\t\t\tvalue instanceof ValueProvider ||\n\t\t\t\tBeanUtil.isReadableBean(value.getClass())) {\n\t\t\tif(value instanceof Map && this.beanClass.isInterface()) {\n\t\t\t\t// 将Map动态代理为Bean\n\t\t\t\treturn MapProxy.create((Map<?, ?>)value).toProxyBean(this.beanClass);\n\t\t\t}\n\n\t\t\t//限定被转换对象类型\n\t\t\treturn BeanCopier.create(value, ReflectUtil.newInstanceIfPossible(this.beanClass), this.beanType, this.copyOptions).copy();\n\t\t} else if(value instanceof byte[]){\n\t\t\t// 尝试反序列化\n\t\t\treturn ObjectUtil.deserialize((byte[])value);\n\t\t} else if(StrUtil.isEmptyIfStr(value)){\n\t\t\t// issue#3136\n\t\t\treturn null;\n\t\t}\n\n\t\tthrow new ConvertException(\"Unsupported source type: {}\", value.getClass());\n\t}\n\n\t@Override\n\tpublic Class<T> getTargetType() {\n\t\treturn this.beanClass;\n\t}\n}\n","sourceCodeStart":80,"sourceCodeEnd":106,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/convert/impl/BeanConverter.java#L80-L106","documentation":"BeanConverter.convertInternal only accepts Map, ValueProvider, a readable Bean, or byte[] (Java-serialized). Any other source type (and not an empty string) reaches the final throw of ConvertException.","triggerScenarios":"Calling BeanConverter on a Number, primitive wrapper, single String scalar, enum, or arbitrary non-bean object that is not a Map/byte[]/ValueProvider.","commonSituations":"Generic pipeline routing a scalar value into a Bean target; misconfigured CopyOptions; calling Convert.convert(scalar, BeanType.class) where scalar cannot seed the bean.","solutions":["Wrap the scalar in a Map keyed by the target bean's field names before converting.","Use the correct converter for the source (NumberConverter, DateConverter, etc.) instead of BeanConverter.","Implement ValueProvider for dynamic field resolution and pass that."],"exampleFix":"// before - scalar cannot seed bean\nUser u = Convert.convert(42, User.class);\n\n// after - wrap in a map\nMap<String,Object> src = new HashMap<>();\nsrc.put(\"id\", 42);\nUser u = Convert.convert(src, User.class);","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof Map) && !(value instanceof ValueProvider)\n        && !(value instanceof byte[]) && !BeanUtil.isReadableBean(value.getClass())) {\n    // wrap in a Map or pick the right converter\n    value = Collections.singletonMap(\"value\", value);\n}\nbeanConverter.convert(value, null);","typeGuard":"value instanceof Map || value instanceof byte[] || BeanUtil.isReadableBean(value.getClass())","tryCatchPattern":"try {\n    return beanConverter.convert(value, null);\n} catch (ConvertException e) {\n    if (e.getMessage().startsWith(\"Unsupported source type\")) { /* wrap source as Map */ }\n    else throw e;\n}","preventionTips":["Wrap scalar sources in a Map before bean conversion.","Choose the converter that matches the source type instead of forcing BeanConverter."],"tags":["convert","bean","type-mismatch"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}