This document maps current behavior to JSON-RPC 2.0 requirements.
- JSON-RPC 2.0: https://www.jsonrpc.org/specification
- RFC 8259 (JSON): https://www.rfc-editor.org/rfc/rfc8259
| Rule | Spec Requirement | Implementation Behavior |
|---|---|---|
jsonrpc field |
MUST be string "2.0" |
Validated; otherwise -32600 Invalid Request |
method field |
MUST be string | Validated non-null/non-blank; otherwise -32600 |
params field |
MAY be array/object | If present and not array/object -> default -32602 Invalid params (configurable to -32600 Invalid Request via validator policy / Spring property) |
id field type |
String/Number/Null (if present) | Invalid id type -> -32600; error response id normalized to null |
| Notification | Request without id |
Invoked with no response payload |
| Success response | MUST contain result (no error) |
Enforced by JsonRpcResponse invariant |
| Error response | MUST contain error (no result) |
Enforced by JsonRpcResponse invariant |
| Parse error | Invalid JSON text | -32700 Parse error, id: null |
| Method not found | Unknown method | -32601 Method not found |
| Internal error | Unhandled runtime/checked exceptions | -32603 Internal error |
| Batch request | Array of requests | Supported |
| Empty batch | Invalid request | Single error object with -32600 |
| Notification-only batch | No response | HTTP adapter returns no body |
| Code | Meaning |
|---|---|
-32700 |
Parse error |
-32600 |
Invalid Request |
-32601 |
Method not found |
-32602 |
Invalid params |
-32603 |
Internal error |
Implementation constants are in JsonRpcErrorCode and messages in JsonRpcConstants.
- Transport parses bytes into JSON.
- Invalid JSON or whitespace-only body is treated as parse error (
-32700). - Dispatcher validates request object shape.
- Method handler is resolved.
- Params are bound/invoked.
- Result or error is composed into JSON-RPC response.
jsonrpc-core also provides response-side protocol utilities:
JsonRpcEnvelopeClassifierJsonRpcErrorClassifierJsonRpcResponseParserJsonRpcResponseValidatorJsonRpcResponseValidationOptions
DefaultJsonRpcResponseParser can parse from JsonNode, String, or byte[], and can optionally reject duplicate
members during raw JSON parsing.
These APIs are transport-agnostic and useful for bidirectional channels (for example WebSocket) where request/response envelopes may arrive on the same connection.
JsonRpcErrorClassifier interprets integer error.code values as:
STANDARD:-32700,-32600,-32601,-32602,-32603SERVER_RESERVED_RANGE:-32099..-32000CUSTOM: any other integer value
CUSTOM does not mean the code is invalid. It only means the code is outside the standard set and the reserved
server-error range.
By default, JsonRpcResponseValidationOptions.defaults() enforces:
- top-level response is an object
jsonrpcequals"2.0"idmember exists and isstring | number | null- exactly one of
resultorerroris present - when
erroris present:erroris an objecterror.codeis an integererror.messageis a string
RFC SHOULD or stricter interoperability policies are configurable via per-rule options. This library does not expose predefined strict/lenient modes; policy is controlled per rule.
JsonRpcResponseValidationOptions exposes per-rule switches:
requireJsonRpcVersion20(default:true)requireIdMember(default:true)allowNullId(default:true)allowStringId(default:true)allowNumericId(default:true)allowFractionalId(default:true)requireExclusiveResultOrError(default:true)requireErrorObjectWhenPresent(default:true)requireIntegerErrorCode(default:true)requireStringErrorMessage(default:true)rejectRequestFields(default:false)rejectDuplicateMembers(default:false)errorCodePolicy(default:ANY_INTEGER)errorCodeRangeMin/errorCodeRangeMax(default:null, used withCUSTOM_RANGE)
rejectRequestFields=false is a compatibility default and is not an RFC MUST rule.
- Notification is defined by absence of
idfield (idPresent == false). "id": nullis not treated as notification; it is still considered present.- For malformed requests where
idexists but type is not allowed (for example object/array), response usesid: null.
- Batch input must be a JSON array.
- Each entry is evaluated independently.
- Non-object entries in batch produce
Invalid Requestresponses. - Responses include only non-notification calls.
- Result list order follows input traversal order.
Methods starting with rpc. are treated as invalid requests during request validation (-32600).
Default in-memory registration also rejects rpc.* method names (IllegalArgumentException), so both registration and
dispatch paths preserve reserved namespace semantics.
Default WebMVC strategy returns:
200 OKfor single/batch, including protocol errors204 No Contentfor notification-only execution
This is transport policy, not protocol rule, and can be overridden via JsonRpcHttpStatusStrategy.
- Oversized request body (
jsonrpc.max-request-bytes) maps to protocol error-32600with messageRequest payload too large. - Parse errors always use
id: null. - Generic exceptions are intentionally normalized to
-32603to avoid leaking internals. paramstype violations (non-array/object) default to-32602; in Spring Boot this can be changed withjsonrpc.validation.request.params-type-violation-code-policy=INVALID_REQUEST.