spring-projects/spring-ai · error · java.lang.IllegalArgumentException
Unsupported value type:
Error message
Unsupported value type:
What it means
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.
Source
Thrown at models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/ConverseApiUtils.java:77
return Document.fromNumber(floatValue);
}
else if (value instanceof Double doubleValue) {
return Document.fromNumber(doubleValue);
}
else if (value instanceof BigDecimal bigDecimalValue) {
return Document.fromNumber(bigDecimalValue);
}
else if (value instanceof BigInteger bigIntegerValue) {
return Document.fromNumber(bigIntegerValue);
}
else if (value instanceof List listValue) {
return Document.fromList(listValue.stream().map(v -> convertObjectToDocument(v)).toList());
}
else if (value instanceof Map mapValue) {
return convertMapToDocument(mapValue);
}
else {
throw new IllegalArgumentException("Unsupported value type:" + value.getClass().getSimpleName());
}
}
public static Map<String, String> getRequestMetadata(Map<String, Object> metadata) {
if (metadata.isEmpty()) {
return Map.of();
}
Map<String, String> result = new HashMap<>();
for (Map.Entry<String, Object> entry : metadata.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key != null && value != null) {
result.put(key, value.toString());
}
}View on GitHub (pinned to 98a7beda4f)
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.
Example fix
// before
options.put("timestamp", new Date());
// after
options.put("timestamp", Instant.now().toString()); Defensive patterns
Strategy: type-guard
Validate before calling
for (Object v : options.values()) {
if (!(v instanceof String || v instanceof Number || v instanceof Boolean
|| v instanceof Map || v instanceof List)) {
throw new IllegalArgumentException("Unsupported option value type: " + v.getClass());
}
} Type guard
static boolean isDocumentConvertible(Object v) {
return v instanceof String || v instanceof Boolean || v instanceof Number
|| v instanceof Map || v instanceof List;
} Try / catch
try {
doc = ConverseApiUtils.convertObjectToDocument(value);
} catch (IllegalArgumentException e) {
// fall back to value.toString() or a Map conversion
} Prevention
- 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
When it happens
Trigger: 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().
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Invalid Image content type:
- Unsupported document format:
- Expected Expression but got:
- Expected Value but got:
- The region '<region>' is not a valid region!
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/fccb046e925b8e12.
Report an issue: GitHub.