{"record":{"id":"fccb046e925b8e12","repo":"spring-projects/spring-ai","slug":"unsupported-value-type","errorCode":null,"errorMessage":"Unsupported value type:","messagePattern":"Unsupported value type:","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/ConverseApiUtils.java","lineNumber":77,"sourceCode":"\t\t\treturn Document.fromNumber(floatValue);\n\t\t}\n\t\telse if (value instanceof Double doubleValue) {\n\t\t\treturn Document.fromNumber(doubleValue);\n\t\t}\n\t\telse if (value instanceof BigDecimal bigDecimalValue) {\n\t\t\treturn Document.fromNumber(bigDecimalValue);\n\t\t}\n\t\telse if (value instanceof BigInteger bigIntegerValue) {\n\t\t\treturn Document.fromNumber(bigIntegerValue);\n\t\t}\n\t\telse if (value instanceof List listValue) {\n\t\t\treturn Document.fromList(listValue.stream().map(v -> convertObjectToDocument(v)).toList());\n\t\t}\n\t\telse if (value instanceof Map mapValue) {\n\t\t\treturn convertMapToDocument(mapValue);\n\t\t}\n\t\telse {\n\t\t\tthrow new IllegalArgumentException(\"Unsupported value type:\" + value.getClass().getSimpleName());\n\t\t}\n\t}\n\n\tpublic static Map<String, String> getRequestMetadata(Map<String, Object> metadata) {\n\n\t\tif (metadata.isEmpty()) {\n\t\t\treturn Map.of();\n\t\t}\n\n\t\tMap<String, String> result = new HashMap<>();\n\t\tfor (Map.Entry<String, Object> entry : metadata.entrySet()) {\n\t\t\tString key = entry.getKey();\n\t\t\tObject value = entry.getValue();\n\n\t\t\tif (key != null && value != null) {\n\t\t\t\tresult.put(key, value.toString());\n\t\t\t}\n\t\t}","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/ConverseApiUtils.java#L59-L95","documentation":"ConverseApiUtils.convertObjectToDocument() converts a Java object into a software.amazon.awssdk Document for Bedrock request fields. It handles List, Map, String, Boolean, and numeric types; anything else (e.g. arbitrary POJOs, dates, enums) falls through to the else branch and throws IllegalArgumentException naming the offending class.","triggerScenarios":"Putting an unsupported object type (e.g. a custom POJO, java.util.Date, BigDecimal in some paths) into a generation option map (BedrockChatOptions) or metadata map that is converted via attr()/convertObjectToDocument().","commonSituations":"Users putting custom option values into BedrockChatOptions (e.g. providerExtensions with raw POJOs); metadata containing complex objects; version changes adding new option types not covered by the converter.","solutions":["Convert the value to a supported type (String, Number, Boolean, Map, List) before adding it to the options/metadata.","For POJOs, serialize to Map<String,Object> or a JSON string first.","Use convertMapToDocument-style helpers for nested structures.","Avoid Date/enum objects; use their string representations."],"exampleFix":"// before\noptions.put(\"timestamp\", new Date());\n// after\noptions.put(\"timestamp\", Instant.now().toString());","handlingStrategy":"type-guard","validationCode":"for (Object v : options.values()) {\n    if (!(v instanceof String || v instanceof Number || v instanceof Boolean\n          || v instanceof Map || v instanceof List)) {\n        throw new IllegalArgumentException(\"Unsupported option value type: \" + v.getClass());\n    }\n}","typeGuard":"static boolean isDocumentConvertible(Object v) {\n    return v instanceof String || v instanceof Boolean || v instanceof Number\n        || v instanceof Map || v instanceof List;\n}","tryCatchPattern":"try {\n    doc = ConverseApiUtils.convertObjectToDocument(value);\n} catch (IllegalArgumentException e) {\n    // fall back to value.toString() or a Map conversion\n}","preventionTips":["Only put primitives, Strings, Maps, and Lists into BedrockChatOptions/metadata","Serialize POJOs and dates to strings before adding","Check for new option type support after upgrading spring-ai"],"tags":["bedrock","type-mismatch","conversion","document"],"backgroundTag":"type-mismatch","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}