{"record":{"id":"b947a26790476414","repo":"alibaba/spring-ai-alibaba","slug":"failed-to-build-json-rpc-streaming-payload","errorCode":null,"errorMessage":"Failed to build JSON-RPC streaming payload","messagePattern":"Failed to build JSON-RPC streaming 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":752,"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/stream\");\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 streaming payload\", e);\n\t\t}\n\t}\n\n\tprivate String getEffectiveInstruction(OverAllState state) {\n\t\tif (StringUtils.hasLength(this.instruction)) {\n\t\t\tPromptTemplate template = PromptTemplate.builder().template(this.instruction).build();\n\t\t\treturn template.render(state.data());\n\t\t} else if (!shareState || (shareState && state.value(\"messages\").isEmpty())) {\n\t\t\tthrow new IllegalStateException(\"Instruction is empty and shareState is false\");\n\t\t}\n\t\treturn \"\";\n\t}\n\n\t/**\n\t * Send the request to the remote A2A server and return the non-streaming response.\n\t * @param agentCard Agent card (source for server URL/metadata)\n\t * @param requestPayload JSON string payload built by buildSendMessageRequest\n\t * @return Response body as string","sourceCodeStart":734,"sourceCodeEnd":770,"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#L734-L770","documentation":"Same serialization guard as the non-streaming payload builder, but for the message/stream (SSE) JSON-RPC request. writeValueAsString failure on the streaming request root object raises this IllegalStateException with the streaming-specific message.","triggerScenarios":"Building the message/stream payload when a value contributed to params (rendered instruction, message text, context/state-derived fields) cannot be serialized by Jackson.","commonSituations":"Non-serializable state values streamed requests share with non-streaming; custom state objects without getters; missing Jackson module for a type used in streaming params.","solutions":["Use only JSON-serializable values in the fields that feed the streaming payload","Inspect the wrapped cause exception for the exact serialization failure and fix that type","Ensure ObjectMapper has required modules registered"],"exampleFix":"// before\nroot.put(\"params\", Map.of(\"ctx\", someComplexObject));\n// after\nroot.put(\"params\", Map.of(\"ctx\", someComplexObject.toString()));","handlingStrategy":"validation","validationCode":"// serialize a dry-run payload before sending\ntry { objectMapper.writeValueAsString(root); } catch (Exception e) { /* fix types first */ }","typeGuard":null,"tryCatchPattern":"try {\n    String payload = action.buildStreamingPayload(state);\n} catch (IllegalStateException e) {\n    // log cause; fix unserializable param values\n}","preventionTips":["Use JSON-safe types in fields feeding the streaming params","Verify custom types have getters or Jackson serializers","Cover payload building in unit tests with representative state"],"tags":["a2a","json","serialization","streaming"],"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"}