{"record":{"id":"a8d9bc4a2f1df087","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-build-json-rpc-payload","errorCode":null,"errorMessage":"Failed to build JSON-RPC payload","messagePattern":"Failed to build JSON-RPC payload","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/a2a/A2aNodeActionWithConfig.java","lineNumber":709,"sourceCode":"\t\tparams.put(\"message\", message);\n\n\t\tMap<String, Object> metadata = new HashMap<>();\n\t\tconfig.threadId().ifPresent(threadId -> metadata.put(\"threadId\", threadId));\n\t\t// FIXME, the key 'userId' should be configurable\n\t\tconfig.metadata(\"userId\").ifPresent(userId -> metadata.put(\"userId\", userId));\n\t\tparams.put(\"metadata\", metadata);\n\n\t\tMap<String, Object> root = new HashMap<>();\n\t\troot.put(\"id\", id);\n\t\troot.put(\"jsonrpc\", \"2.0\");\n\t\troot.put(\"method\", \"message/send\");\n\t\troot.put(\"params\", params);\n\n\t\ttry {\n\t\t\treturn objectMapper.writeValueAsString(root);\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new IllegalStateException(\"Failed to build JSON-RPC payload\", e);\n\t\t}\n\t}\n\n\t/**\n\t * Build the JSON-RPC streaming request payload (method: message/stream).\n\t * @param state Parent state\n\t * @return JSON string payload for streaming\n\t */\n\tprivate String buildSendStreamingMessageRequest(OverAllState state, RunnableConfig config) {\n\t\tObject textValue = getEffectiveInstruction(state);\n\t\tString text = String.valueOf(textValue);\n\n\t\tString id = UUID.randomUUID().toString();\n\t\tString messageId = UUID.randomUUID().toString().replace(\"-\", \"\");\n\n\t\tMap<String, Object> part = Map.of(\"kind\", \"text\", \"text\", text);\n\n\t\tMap<String, Object> message = new HashMap<>();","sourceCodeStart":691,"sourceCodeEnd":727,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-agent-framework/src/main/java/com/alibaba/cloud/ai/graph/agent/a2a/A2aNodeActionWithConfig.java#L691-L727","documentation":"Building the JSON-RPC message/send request body uses Jackson ObjectMapper.writeValueAsString; if serialization fails (unserializable value in state-derived params), the method wraps it in this IllegalStateException. Essentially a defensive wrap around JSON generation of the A2A request.","triggerScenarios":"getEffectiveInstruction/rendered template or state values placed into the params map cannot be serialized by Jackson (e.g. an object with no properties, infinite recursion, or an unsupported type like InputStream).","commonSituations":"Passing Java objects (streams, custom classes without getters) into agent state that end up rendered into the payload; template rendering producing an object Jackson can't handle; misconfigured ObjectMapper modules.","solutions":["Ensure values read from state are JSON-friendly (String, Number, Map, List) before they go into params","Register needed Jackson modules (e.g. JavaTimeModule) or configure the ObjectMapper correctly","Log/catch the cause (the exception carries the underlying JsonProcessingException) and fix the offending field"],"exampleFix":"// before\nstate.put(\"attachment\", new FileInputStream(file)); // unserializable\n// after\nstate.put(\"attachment\", Files.readString(file.toPath()));","handlingStrategy":"validation","validationCode":"// ensure state values are JSON-friendly before building the request\nboolean serializable(Object o) {\n    try { new ObjectMapper().writeValueAsString(o); return true; }\n    catch (Exception e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n    String payload = action.buildPayload(state);\n} catch (IllegalStateException e) {\n    // inspect cause (JsonProcessingException) and fix the unserializable value\n}","preventionTips":["Keep only String/Number/Map/List values in graph state","Register Jackson modules for custom types","Log the wrapped cause to identify the offending field"],"tags":["a2a","json","serialization"],"backgroundTag":"json-marshal-failed","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"}