alibaba/spring-ai-alibaba · error · IllegalArgumentException
Unsupported body type: {raw.getClass()}
Error message
Unsupported body type: {raw.getClass()} What it means
HttpNode's HttpRequestNodeBody.of(...) converts a raw request-body value into a typed HttpRequestNodeBody based on its runtime class. When the raw value is not one of the handled types (String, JSON structures, etc.) the switch falls through and an IllegalArgumentException naming the offending class is thrown. It is a static type-dispatch guard: the body type configured for the HTTP request node is not supported.
Source
Thrown at spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/HttpNode.java:704
Object fn = item.get("filename");
if (fn instanceof String) {
bd5.setFilename((String) fn);
}
Object mt = item.get("mimeType");
if (mt instanceof String) {
bd5.setMimeType((String) mt);
}
list3.add(bd5);
}
return new HttpRequestNodeBody(BodyType.BINARY, list3);
}
return new HttpRequestNodeBody(BodyType.NONE, null);
default:
return new HttpRequestNodeBody(BodyType.NONE, null);
}
}
throw new IllegalArgumentException("Unsupported body type: " + raw.getClass());
}
public BodyType getType() {
return type;
}
public void setType(BodyType type) {
this.type = type;
}
public List<BodyData> getData() {
return data;
}
public void setData(List<BodyData> data) {
this.data = data;
}
View on GitHub (pinned to f82da0b50f)
Solutions
- Convert the body to a supported representation (e.g. JSON String) before passing it to of(...).
- Check the default branch of the switch to see exactly which classes are supported and which class is being passed.
- If a new type is genuinely needed, add a case for it in the switch mapping to the correct BodyType.
- Validate bodyType vs raw payload at node-build time to fail early with a clearer message.
Example fix
// before HttpRequestNodeBody body = HttpRequestNodeBody.of(myPojo); // after HttpRequestNodeBody body = HttpRequestNodeBody.of(objectMapper.writeValueAsString(myPojo));
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(raw instanceof String) && !(raw instanceof Map) && !(raw instanceof List)) {
throw new IllegalArgumentException("HTTP body must be String/Map/List, got " + raw.getClass());
} Type guard
boolean isSupportedBodyType(Object raw) {
return raw instanceof String || raw instanceof Map<?,?> || raw instanceof List<?>;
} Try / catch
try {
HttpRequestNodeBody body = HttpRequestNodeBody.of(raw);
} catch (IllegalArgumentException e) {
raw = objectMapper.writeValueAsString(raw); // fallback to JSON string
HttpRequestNodeBody body = HttpRequestNodeBody.of(raw);
} Prevention
- Pass bodies as JSON strings unless the API documents structured types.
- Don't pass POJOs/byte[] directly into body factories.
- Validate bodyType/raw pairing at node construction.
- Add a unit test for every BodyType you configure.
When it happens
Trigger: Configuring an HttpExecuter/HttpRequestNodeBody with a raw body object whose class is not handled by the switch — e.g. passing a POJO, byte[], Map of unexpected shape, or null-typed object where only String/structured types are supported.
Common situations: Users set the HTTP node request body to a serialized Java object instead of a JSON string; workflow DSL yields a typed value the body factory doesn't recognize; refactors change bodyType/raw value pairing inconsistently.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Tool not found with id: <id>
- Unknown agent status code:
- Unknown agent type code:
- Invalid MessageType value:
- Invalid status:
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/48b59c3230c32e67.
Report an issue: GitHub.