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 invokeparams- 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ObjectThe request identifier.protected StringThe JSON-RPC protocol version.protected StringThe method name to invoke.protected TThe method parameters.Fields inherited from interface org.a2aproject.sdk.jsonrpc.common.wrappers.A2AMessage
JSONRPC_VERSION -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetId()Gets the request/response correlation identifier.Gets the JSON-RPC version for this message.Gets the name of the method to be invoked.Gets the parameters to be passed to the method.protected voidvalidateAndSetJsonParameters(String jsonrpc, String method, Object id, T params, boolean paramsIsRequired) Validates and sets JSON-RPC parameters.
-
Field Details
-
jsonrpc
The JSON-RPC protocol version. -
id
The request identifier. -
method
The method name to invoke. -
params
The method parameters.
-
-
Constructor Details
-
A2ARequest
public A2ARequest()Default constructor for JSON deserialization.
-
-
Method Details
-
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:
getJsonrpcin interfaceA2AMessage- Returns:
- the JSON-RPC version string, always "2.0"
-
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:
getIdin interfaceA2AMessage- Returns:
- the correlation ID, or null for notifications
-
getMethod
Gets the name of the method to be invoked.- Returns:
- the method name
-
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 versionmethod- the method nameid- the request IDparams- the parametersparamsIsRequired- whether parameters are required
-