Package org.moera.lib.jsonrpc
Class JsonRpcRequest
java.lang.Object
org.moera.lib.jsonrpc.JsonRpcRequest
Represents a JSON-RPC 2.0 request as specified by the JSON-RPC protocol.
This class contains the structure required for a compliant JSON-RPC request.
JSON-RPC is a lightweight remote procedure call protocol encoded in JSON. Each request includes a method name, optional parameters, and an identifier that allows for asynchronous processing of requests.
The JsonRpcRequest
class supports setting and retrieving the following properties:
- jsonrpc
: Specifies the JSON-RPC protocol version (hardcoded to "2.0").
- method
: Specifies the method to be invoked on the remote server.
- params
: Provides the parameters to be passed to the method (if applicable).
- id
: Identifies the request to match it with a corresponding response.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetId()
Retrieves the identifier of the JSON-RPC request.Retrieves the JSON-RPC protocol version used in the request.Retrieves the name of the method to be invoked in the JSON-RPC request.com.fasterxml.jackson.databind.JsonNode
Retrieves the parameters associated with the JSON-RPC request.void
Sets the identifier for this JSON-RPC request.void
Sets the name of the JSON-RPC method to be invoked in the request.void
setParams
(com.fasterxml.jackson.databind.JsonNode params) Sets the parameters to be passed to the remote method in a JSON-RPC request.
-
Constructor Details
-
JsonRpcRequest
public JsonRpcRequest()
-
-
Method Details
-
getJsonrpc
Retrieves the JSON-RPC protocol version used in the request.- Returns:
- the JSON-RPC protocol version as a string, always "2.0".
-
getMethod
Retrieves the name of the method to be invoked in the JSON-RPC request.- Returns:
- the method name as a string, which represents the procedure to be executed on the server.
-
setMethod
Sets the name of the JSON-RPC method to be invoked in the request. The method name must correspond to a valid procedure on the JSON-RPC server.- Parameters:
method
- the name of the method to be invoked. It cannot benull
or empty and should adhere to the JSON-RPC protocol specifications.
-
getParams
public com.fasterxml.jackson.databind.JsonNode getParams()Retrieves the parameters associated with the JSON-RPC request.- Returns:
- the parameters of the request as a
JsonNode
, ornull
if no parameters are set.
-
setParams
public void setParams(com.fasterxml.jackson.databind.JsonNode params) Sets the parameters to be passed to the remote method in a JSON-RPC request.- Parameters:
params
- the parameters to be sent with the JSON-RPC request. This is expected to be a JSON structure represented by aJsonNode
.
-
getId
Retrieves the identifier of the JSON-RPC request.- Returns:
- an
Object
representing the identifier of the request. The identifier is used to match the request with its corresponding response.
-
setId
Sets the identifier for this JSON-RPC request.- Parameters:
id
- the identifier to associate with this request. It can be used to match the request with its corresponding response.
-