{"record":{"id":"2041a4cb0cfa16a6","repo":"alibaba/spring-ai-alibaba","slug":"unsupported-message-type","errorCode":null,"errorMessage":"Unsupported message type: {}","messagePattern":"Unsupported message type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/serializer/std/MessageSerializer.java","lineNumber":50,"sourceCode":"\n\tfinal UserMessageSerializer user = new UserMessageSerializer();\n\n\tfinal AssistantMessageSerializer assistant = new AssistantMessageSerializer();\n\n\tfinal SystemMessageSerializer system = new SystemMessageSerializer();\n\n\tfinal ToolResponseMessageSerializer tool = new ToolResponseMessageSerializer();\n\n\t@Override\n\tpublic void write(Message object, ObjectOutput out) throws IOException {\n\t\tout.writeObject(object.getMessageType());\n\n\t\tswitch (object.getMessageType()) {\n\t\t\tcase USER -> user.write((UserMessage) object, out);\n\t\t\tcase ASSISTANT -> assistant.write((AssistantMessage) object, out);\n\t\t\tcase SYSTEM -> system.write((SystemMessage) object, out);\n\t\t\tcase TOOL -> tool.write((ToolResponseMessage) object, out);\n\t\t\tdefault -> throw new IllegalArgumentException(\"Unsupported message type: \" + object.getMessageType());\n\t\t}\n\t}\n\n\t@Override\n\tpublic Message read(ObjectInput in) throws IOException, ClassNotFoundException {\n\n\t\tMessageType type = (MessageType) in.readObject();\n\n\t\treturn switch (type) {\n\t\t\tcase ASSISTANT -> assistant.read(in);\n\t\t\tcase USER -> user.read(in);\n\t\t\tcase SYSTEM -> system.read(in);\n\t\t\tcase TOOL -> tool.read(in);\n\t\t};\n\t}\n\n}\n","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-graph-core/src/main/java/com/alibaba/cloud/ai/graph/serializer/std/MessageSerializer.java#L32-L68","documentation":"MessageSerializer.write dispatches on the message's MessageType enum (USER, ASSISTANT, SYSTEM, TOOL). Any other or unknown enum constant has no registered writer, so an IllegalArgumentException is thrown. This guards against new/unknown Spring AI message types being written with a serializer that does not support them.","triggerScenarios":"Serializing a Message whose getMessageType() returns a value outside the four handled cases — e.g. a custom Message implementation, a newly added MessageType from a newer Spring AI version, or null/aliased message types.","commonSituations":"Upgrading Spring AI introduces a new message type the framework serializer does not yet handle; passing custom message subclasses through graph state serialization; mixing library versions between serializer and message classes.","solutions":["Check the message type actually flowing into state; convert unsupported message types to a supported one (e.g. wrap content in an AssistantMessage) before serialization","Align spring-ai and spring-ai-alibaba versions so the message enum matches what the serializer supports","Upgrade spring-ai-alibaba to a version that handles the new message type","Register/patch the serializer chain to add a writer for the custom message type"],"exampleFix":"// before: custom message type hits default branch\nstate.put(\"msg\", new MyCustomMessage(\"hi\"));\n// after: normalize to a supported type\nstate.put(\"msg\", new UserMessage(\"hi\"));","handlingStrategy":"type-guard","validationCode":"Set<MessageType> supported = Set.of(MessageType.USER, MessageType.ASSISTANT, MessageType.SYSTEM, MessageType.TOOL);\nif (msg != null && !supported.contains(msg.getMessageType())) throw new IllegalArgumentException(\"Unsupported message type: \" + msg.getMessageType());","typeGuard":"boolean isSerializableMessageType(Message m) {\n    return m != null && EnumSet.of(MessageType.USER, MessageType.ASSISTANT, MessageType.SYSTEM, MessageType.TOOL).contains(m.getMessageType());\n}","tryCatchPattern":"try { serializer.write(msg, out); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Unsupported message type\")) { out.writeObject(new UserMessage(((Message) msg).getText())); } else throw e; }","preventionTips":["Normalize custom/unknown messages to UserMessage/AssistantMessage before storing in state","Keep Spring AI and spring-ai-alibaba versions aligned","Add a serialization smoke test covering all message types your app produces"],"tags":["serialization","messages","enum"],"backgroundTag":"unsupported-enum-value","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}