{"record":{"id":"be0185afdba64d12","repo":"dotnet/aspnetcore","slug":"error-reading-json","errorCode":null,"errorMessage":"Error reading JSON.","messagePattern":"Error reading JSON\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/GsonHubProtocol.java","lineNumber":220,"sourceCode":"                    case STREAM_INVOCATION:\n                    case CANCEL_INVOCATION:\n                        throw new UnsupportedOperationException(String.format(\"The message type %s is not supported yet.\", messageType));\n                    case PING:\n                        hubMessages.add(PingMessage.getInstance());\n                        break;\n                    case CLOSE:\n                        if (error != null) {\n                            hubMessages.add(new CloseMessage(error));\n                        } else {\n                            hubMessages.add(new CloseMessage());\n                        }\n                        break;\n                    default:\n                        break;\n                }\n            }\n        } catch (IOException ex) {\n            throw new RuntimeException(\"Error reading JSON.\", ex);\n        }\n\n        return hubMessages;\n    }\n\n    @Override\n    public ByteBuffer writeMessage(HubMessage hubMessage) {\n        return ByteBuffer.wrap((gson.toJson(hubMessage) + RECORD_SEPARATOR).getBytes(StandardCharsets.UTF_8));\n    }\n\n    private ArrayList<Object> bindArguments(JsonArray argumentsToken, List<Type> paramTypes) {\n        if (argumentsToken.size() != paramTypes.size()) {\n            throw new RuntimeException(String.format(\"Invocation provides %d argument(s) but target expects %d.\", argumentsToken.size(), paramTypes.size()));\n        }\n\n        ArrayList<Object> arguments = null;\n        if (paramTypes.size() >= 1) {\n            arguments = new ArrayList<>();","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/92f07e298d5c5a629385b8b0a32d7164b1b53906/src/SignalR/clients/java/signalr/core/src/main/java/com/microsoft/signalr/GsonHubProtocol.java#L202-L238","documentation":"GsonHubProtocol.parseMessages wraps the entire message-parsing loop in a try/catch(IOException) and rethrows as RuntimeException(\"Error reading JSON.\", ex) at line 220. The raw bytes from the transport could not be parsed into valid JSON: truncated frames, encoding corruption, non-JSON data, or a protocol mismatch (e.g. server using MessagePack while client expects JSON).","triggerScenarios":"A partially-delivered or corrupted frame arrives over the transport; the JsonReader throws an IOException mid-parse; the catch at line 219 wraps it. Also happens if the server emits MessagePack (binary) to a JSON-only client, or a proxy/intermediary rewrites the payload.","commonSituations":"Server configured for MessagePack while the Java client uses the default GsonHubProtocol; network proxies/WAFs truncating or rewriting WebSocket frames; flaky connections delivering partial reads; client/server major version mismatch changing the wire format.","solutions":["Verify both server and client use the JSON hub protocol (the Java client does not support MessagePack).","Check the wrapped IOException in the stack trace for the exact parse failure location.","Inspect the network path (proxies, load balancers, TLS terminators) for payload corruption.","Upgrade client and server to matching versions of the SignalR protocol."],"exampleFix":"// before: server configured to prefer MessagePack\n//   services.AddSignalR().AddMessagePackProtocol();\n// after: ensure JSON protocol is available to the Java client\n//   services.AddSignalR(); // JSON is default and supported by the Java client","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Guard the receive/parse path; JSON parse failures are unrecoverable for that frame\nconn.onClosed(err -> {\n    if (err != null && err.getMessage() != null && err.getMessage().contains(\"Error reading JSON\")) {\n        log.error(\"Protocol parse failure; check protocol/network path\", err);\n    }\n});","preventionTips":["Ensure both ends use the JSON protocol (Java client has no MessagePack support).","Avoid proxies/WAFs that rewrite WebSocket frames.","Keep client and server on matching SignalR versions."],"tags":["signalr","java","json","parsing","network","gsonhubprotocol"],"analyzedSha":"92f07e298d5c5a629385b8b0a32d7164b1b53906","analyzedAt":"2026-08-07T06:05:17.747Z","schemaVersion":2},"datasetVersion":"2026-08-07T15:17:06.553Z"}