{"record":{"id":"4ccc56184ed09a98","repo":"chinabugotech/hutool","slug":"unsupported-source-type-to","errorCode":null,"errorMessage":"Unsupported source type: [{}] to [{}]","messagePattern":"Unsupported source type: \\[(.+?)\\] to \\[(.+?)\\]","errorType":"exception","errorClass":"ConvertException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/convert/impl/RecordConverter.java","lineNumber":46,"sourceCode":"\t}\n\n\t@SuppressWarnings(\"unchecked\")\n\t@Override\n\tpublic Object convert(Object value, Object defaultValue) throws IllegalArgumentException {\n\t\tValueProvider<String> valueProvider = null;\n\t\tif (value instanceof ValueProvider) {\n\t\t\tvalueProvider = (ValueProvider<String>) value;\n\t\t} else if (value instanceof Map) {\n\t\t\tvalueProvider = new MapValueProvider((Map<String, ?>) value);\n\t\t} else if (BeanUtil.isReadableBean(value.getClass())) {\n\t\t\tvalueProvider = new BeanValueProvider(value, false, false);\n\t\t}\n\n\t\tif (null != valueProvider) {\n\t\t\treturn RecordUtil.newInstance(recordClass, valueProvider);\n\t\t}\n\n\t\tthrow new ConvertException(\"Unsupported source type: [{}] to [{}]\", value.getClass(), recordClass);\n\t}\n}\n","sourceCodeStart":28,"sourceCodeEnd":49,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/convert/impl/RecordConverter.java#L28-L49","documentation":"Thrown by RecordConverter.convert() when the source value is not a ValueProvider, a Map, or a 'readable bean' (as decided by BeanUtil.isReadableBean). Record construction requires property-by-property source data, so scalar values like Strings, Numbers, or arbitrary objects that fail the readable-bean check cannot be used to build a Record.","triggerScenarios":"Calling Convert.convert(MyRecord.class, \"someString\") or Convert.convert(MyRecord.class, 42). Passing a POJO with no readable getters (all fields private with no accessors), causing BeanUtil.isReadableBean to return false. Passing an array, Collection, or enum value as the source.","commonSituations":"Deserializing JSON or form data into a Java Record where the JSON deserializer produced a scalar instead of a Map. Attempting to convert a primitive wrapper or String into a multi-field Record. POJOs with only private fields and Lombok @FieldNameConstants or @Builder but no getters, failing isReadableBean.","solutions":["Convert the source to a Map (e.g., Map<String,Object>) before targeting a Record type.","If the source is a POJO, ensure it has public getters or use BeanUtil.toBean() which may handle it through a different path.","Wrap the source in a ValueProvider<String> implementation if you need custom property resolution.","Validate that value.getClass() passes BeanUtil.isReadableBean(value.getClass()) before attempting the Record conversion."],"exampleFix":"// before\nConvert.convert(MyRecord.class, \"{\\\"a\\\":1}\"); // String, not a Map -> throws\n\n// after\nMap<String,Object> map = JSONUtil.toBean(\"{\\\"a\\\":1}\", Map.class);\nMyRecord rec = Convert.convert(MyRecord.class, map);","handlingStrategy":"type-guard","validationCode":"if (!(value instanceof Map) && !(value instanceof ValueProvider)\n    && !BeanUtil.isReadableBean(value.getClass())) {\n    throw new IllegalArgumentException(\"Value must be a Map, ValueProvider, or readable bean\");\n}\nConvert.convert(recordClass, value);","typeGuard":"static boolean canConvertToRecord(Object value) {\n    return value instanceof Map || value instanceof ValueProvider\n        || BeanUtil.isReadableBean(value.getClass());\n}","tryCatchPattern":"try {\n    return Convert.convert(recordClass, value);\n} catch (ConvertException e) {\n    if (e.getMessage().contains(\"Unsupported source type\")) {\n        Map<String,Object> map = BeanUtil.beanToMap(value);\n        return Convert.convert(recordClass, map);\n    }\n    throw e;\n}","preventionTips":["Always convert source data to a Map before targeting a Record type.","Ensure POJOs have readable getters if they will be Record conversion sources.","Validate the source type with canConvertToRecord() before attempting conversion."],"tags":["convert","record","value-provider","bean","convert-exception"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}