Class A2ARequest<T>

java.lang.Object
org.a2aproject.sdk.jsonrpc.common.wrappers.A2ARequest<T>
Type Parameters:
T - the type of the params object for this request
All Implemented Interfaces:
A2AMessage
Direct Known Subclasses:
NonStreamingJSONRPCRequest, StreamingJSONRPCRequest

public abstract sealed class A2ARequest<T> extends Object implements A2AMessage permits NonStreamingJSONRPCRequest<T>, StreamingJSONRPCRequest<T>
Base class for JSON-RPC 2.0 requests in the A2A Protocol.

This sealed class represents a JSON-RPC 2.0 request message with parameterized support for different request parameter types. It enforces the JSON-RPC 2.0 specification requirements while providing type safety through generic parameters.

A JSON-RPC request consists of:

  • jsonrpc - The protocol version (always "2.0")
  • method - The name of the method to invoke
  • params - Method parameters (optional, type varies by method)
  • id - Correlation identifier for matching with responses (optional for notifications)

This class is sealed to ensure only NonStreamingJSONRPCRequest and StreamingJSONRPCRequest can extend it, providing compile-time guarantees about request types.

See Also:
  • Field Details

    • jsonrpc

      protected String jsonrpc
      The JSON-RPC protocol version.
    • id

      protected Object id
      The request identifier.
    • method

      protected String method
      The method name to invoke.
    • params

      protected T params
      The method parameters.
  • Constructor Details

    • A2ARequest

      public A2ARequest()
      Default constructor for JSON deserialization.
  • Method Details

    • getJsonrpc

      public String getJsonrpc()
      Gets the JSON-RPC version for this message.

      According to the JSON-RPC 2.0 specification, this must be exactly "2.0".

      Specified by:
      getJsonrpc in interface A2AMessage
      Returns:
      the JSON-RPC version string, always "2.0"
    • getId

      public Object getId()
      Gets the request/response correlation identifier.

      The ID is used to match responses with their corresponding requests. It may be a String, Integer, or null for notification-style requests that do not expect a response.

      Specified by:
      getId in interface A2AMessage
      Returns:
      the correlation ID, or null for notifications
    • getMethod

      public String getMethod()
      Gets the name of the method to be invoked.
      Returns:
      the method name
    • getParams

      public T getParams()
      Gets the parameters to be passed to the method.
      Returns:
      the method parameters, or null if none
    • validateAndSetJsonParameters

      protected void validateAndSetJsonParameters(String jsonrpc, String method, Object id, T params, boolean paramsIsRequired)
      Validates and sets JSON-RPC parameters.
      Parameters:
      jsonrpc - the JSON-RPC version
      method - the method name
      id - the request ID
      params - the parameters
      paramsIsRequired - whether parameters are required