Package org.moera.lib.jsonrpc
Class JsonRpcResponse
java.lang.Object
org.moera.lib.jsonrpc.JsonRpcResponse
Represents a JSON-RPC response object following the JSON-RPC 2.0 specification.
This class encapsulates the response attributes such as the protocol version,
result, error, and ID associated with the request.
The `JsonRpcResponse` object can either return a successful result or contain error information to indicate a failure.
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for creating an empty instance ofJsonRpcResponse
.JsonRpcResponse
(Object id, int code, String message) Constructs a JSON-RPC response with an error.JsonRpcResponse
(Object id, Object result) Constructs aJsonRpcResponse
object with the specified ID and result.JsonRpcResponse
(Object id, JsonRpcError error) Constructs a JSON-RPC response object with the specified ID and error details.JsonRpcResponse
(Object id, NamingError error) Constructs a newJsonRpcResponse
object with the specified request ID and aNamingError
. -
Method Summary
Modifier and TypeMethodDescriptiongetError()
Retrieves the error associated with the JSON-RPC response.getId()
Retrieves the identifier associated with the JSON-RPC response.Retrieves the JSON-RPC protocol version used in this response.Retrieves the result of the JSON-RPC response.void
setError
(JsonRpcError error) Sets the error attribute of the JSON-RPC response.void
Sets the ID of the JSON-RPC response.void
Sets the result object for the JSON-RPC response.
-
Constructor Details
-
JsonRpcResponse
public JsonRpcResponse()Default constructor for creating an empty instance ofJsonRpcResponse
. -
JsonRpcResponse
Constructs aJsonRpcResponse
object with the specified ID and result.- Parameters:
id
- the identifier for the JSON-RPC request associated with this response. This parameter matches the ID of the request for which the response is being generated.result
- the result value of the JSON-RPC response. It represents the output of the operation performed and can be of any type. If the request was successful, this parameter contains the result value.
-
JsonRpcResponse
Constructs a JSON-RPC response object with the specified ID and error details.- Parameters:
id
- the unique identifier of the JSON-RPC request to which this response corresponds. It can be any object type, depending on the client's implementation.error
- theJsonRpcError
containing error code and message. This represents the error details in the response when the request has failed.
-
JsonRpcResponse
Constructs a newJsonRpcResponse
object with the specified request ID and aNamingError
.- Parameters:
id
- the identifier of the JSON-RPC request, used to match this response to the requesterror
- theNamingError
associated with this response, providing details about the error
-
JsonRpcResponse
Constructs a JSON-RPC response with an error. This constructor is used to signify an error response in the JSON-RPC 2.0 format.- Parameters:
id
- the identifier of the JSON-RPC request. It is used to correlate the response with its corresponding request and can be of any type.code
- the error code that indicates the type of error. Common codes are defined in the JSON-RPC specification, or custom codes may be used.message
- the error message providing additional details about the error.
-
-
Method Details
-
getJsonrpc
Retrieves the JSON-RPC protocol version used in this response.- Returns:
- the JSON-RPC protocol version as a
String
. Typically, this will return "2.0".
-
getResult
Retrieves the result of the JSON-RPC response.- Returns:
- the result object of the response, or
null
if no result is returned or the response contains an error.
-
setResult
Sets the result object for the JSON-RPC response.- Parameters:
result
- the result of the JSON-RPC operation, which can be any object ornull
depending on the success or failure of the corresponding request.
-
getError
Retrieves the error associated with the JSON-RPC response.- Returns:
- the
JsonRpcError
object representing the error details, ornull
if the response does not contain an error.
-
setError
Sets the error attribute of the JSON-RPC response.- Parameters:
error
- theJsonRpcError
object representing the error details associated with the response.
-
getId
Retrieves the identifier associated with the JSON-RPC response. The identifier is used to correlate the response with the original request.- Returns:
- the ID of the response. It can be any object type, including
null
if no identifier was assigned.
-
setId
Sets the ID of the JSON-RPC response. The ID is used to correlate requests and responses in JSON-RPC communication.- Parameters:
id
- the ID to be associated with the response. It can be of any object type.
-