Skip to content

Add RFC-aligned response protocol utilities to jsonrpc-core #15

@limehee

Description

@limehee

Problem statement

jsonrpc-core currently provides first-class request-side protocol processing, but response-side protocol handling is not exposed as a dedicated core API.

To improve JSON-RPC 2.0 protocol completeness and consistency, the core should also provide standardized response envelope classification, parsing, and validation aligned with the specification.

Proposed solution

Add response-side protocol components to jsonrpc-core:

  1. JsonRpcEnvelopeClassifier + JsonRpcEnvelopeType (REQUEST, RESPONSE, INVALID)
  • Classify single and batch payloads into request/response/invalid at protocol level.
  1. JsonRpcResponseParser
  • Parse incoming JSON-RPC response payloads into a canonical incoming-response model.
  • Preserve member-presence semantics (id present, result present, error present).
  1. JsonRpcResponseValidator
  • Enforce JSON-RPC 2.0 response constraints:
    • Top-level response must be an object.
    • jsonrpc MUST be "2.0".
    • id member MUST exist and MUST be string | number | null.
    • Exactly one of result or error MUST be present.
    • If error exists:
      • error MUST be an object.
      • error.code MUST be an integer.
      • error.message MUST be a string.
      • error.data remains optional.
  1. JsonRpcResponseValidationOptions (fine-grained controls)
  • Provide per-rule switches (Jackson-style configuration).
  • Default values must follow RFC MUST constraints.
  • RFC SHOULD / stricter operational rules (for example, rejecting fractional numeric IDs) are opt-in only.
  1. Tests and docs
  • Add unit tests covering success/failure/exception/branch scenarios for classifier/parser/validator.
  • Update docs/protocol-and-compliance.md and docs/pure-java-guide.md with response-side handling and option usage.

Alternatives considered

  • Keep current request-only scope:
    • Leaves response-side protocol handling unspecified in core.
  • Add classifier only:
    • Insufficient for full response protocol correctness.

JSON-RPC behavior impact

No breaking change to existing request dispatch behavior.

This is an additive enhancement in jsonrpc-core to improve protocol completeness and RFC/spec alignment.

Additional context

Scope is strictly protocol-level and transport-agnostic.

No domain-specific policies (session registry, command/event mapping, tenant/edge rules, business status conversion) are included.

Metadata

Metadata

Assignees

Labels

type: featureNew feature specification and implementation.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions