Conversation
…tcher - Transition from artificial namespace routing to strict JSON-RPC 2.0 method mapping. - Update APT `JoobyProcessor` to generate isolated `*Rpc_` classes for each `@JsonRpc` annotated controller. - Preserve standard MVC factory constructor patterns (`Function<Context, T>`) in generated RPC services to maintain full Dependency Injection support. - Introduce `JsonRpcService.getMethods()` to explicitly declare supported protocol methods. - Implement $O(1)$ `HashMap` method resolution in the Tier 1 `JsonRpcDispatcher`. - Remove implicit `Extension` self-registration from generated classes in favor of explicit manual registration via the dispatcher constructor. - Fix `@Generated` annotation metadata output for Java (`.class`) and Kotlin (`::class`). - ref #3868
…ntrollers - Fix an issue where mixing standard REST annotations (e.g., `@GET`, `@Path`) with `@JsonRpc` on the same controller caused the APT processor to exit early, skipping the standard MVC router generation. - Update `JoobyProcessor` to perform two distinct file generation passes, allowing a single controller to output both REST and JSON-RPC routing files simultaneously. - Introduce `hasRestRoutes()` and `hasJsonRpcRoutes()` condition checks to `MvcRouter`. - Refactor the monolithic `toSourceCode()` method into strictly isolated `getRestSourceCode()` and `getRpcSourceCode()` methods. - Ensure standard routes generate `[Name]_` files and JSON-RPC routes generate `[Name]Rpc_` files without filename or class name conflicts. - Fine-tune `CodeBlock` formatting in the JSON-RPC generator, removing manual newline hacks in favor of native block indentation.
- Add `JsonRpcErrorCode` enum mapping core JSON-RPC 2.0 protocol errors (-32700 to -32603) and implementation-defined server errors (-32000 to -32099) to Jooby's standard HTTP `StatusCode`s. - Introduce a `protocol` flag on error codes to cleanly differentiate between transport/parsing faults and application-level exceptions. - Ensure error payloads comply with the 2.0 spec by utilizing the `data` field to hold specific exception messages, keeping the `message` field generic and strictly compliant. - Refactor and expand `JsonRpcProtocolTest` into isolated test methods. - Add comprehensive integration tests for error edge cases: missing/invalid parameters, unknown methods, application exception bubbling, and specific batch processing edge cases (empty arrays, arrays of invalid data).
…ompliance - Add `JsonRpcParser`, `JsonRpcDecoder`, and `JsonRpcReader` implementations for Jackson 2, Jackson 3, and Avaje JSON-B. - Implement custom serializers (`StdSerializer` for Jackson, `JsonAdapter` for Avaje) for `JsonRpcResponse` and `ErrorDetail` to enforce JSON-RPC 2.0 mutual exclusivity (payloads MUST NOT contain both `result` and `error`). - Add robust type coercion to JSON readers to reject invalid primitives and throw `IllegalArgumentException` instead of failing silently. - Refactor `JsonRpcProtocolTest` into `AbstractJsonRpcProtocolTest` to seamlessly run the entire protocol compliance suite against all registered JSON engines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a complete, spec-compliant JSON-RPC 2.0 implementation for Jooby. It leverages Jooby's annotation processing tool (APT) to eliminate boilerplate, mapping standard JSON-RPC requests to native controller methods, and includes core parser/decoder implementations across multiple JSON engines.
Key Changes:
@JsonRpccontrollers. The annotation processor now automatically generates the protocol dispatcher, seamlessly routing JSON-RPCmethodstrings (e.g.,movies.getById) directly to nativeJsonRpcServicemethods without requiring developers to write protocol-specific routing logic.JsonRpcParser,JsonRpcDecoder, andJsonRpcReaderinterfaces for Jackson 2, Jackson 3, and Avaje JSON-B to handle payload deserialization efficiently.resultanderrorsimultaneously) using custom serializers (StdSerializerfor Jackson,JsonAdapter.Factoryfor Avaje).IllegalArgumentException. IntegratedJsonRpcErrorCodeto seamlessly map native application exceptions (like HTTP 404) to JSON-RPC standard error codes (e.g.,-32004) while populating thedatafield.AbstractJsonRpcProtocolTestto execute the entire compliance test suite (including batch processing, invalid params, and parse errors) against all registered JSON modules.