Class JsonRpcResponse

java.lang.Object
org.moera.lib.jsonrpc.JsonRpcResponse

public class JsonRpcResponse extends Object
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 Details

    • JsonRpcResponse

      public JsonRpcResponse()
      Default constructor for creating an empty instance of JsonRpcResponse.
    • JsonRpcResponse

      public JsonRpcResponse(Object id, Object result)
      Constructs a JsonRpcResponse 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

      public JsonRpcResponse(Object id, JsonRpcError error)
      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 - the JsonRpcError containing error code and message. This represents the error details in the response when the request has failed.
    • JsonRpcResponse

      public JsonRpcResponse(Object id, NamingError error)
      Constructs a new JsonRpcResponse object with the specified request ID and a NamingError.
      Parameters:
      id - the identifier of the JSON-RPC request, used to match this response to the request
      error - the NamingError associated with this response, providing details about the error
    • JsonRpcResponse

      public JsonRpcResponse(Object id, int code, String message)
      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

      public String 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

      public Object 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

      public void setResult(Object result)
      Sets the result object for the JSON-RPC response.
      Parameters:
      result - the result of the JSON-RPC operation, which can be any object or null depending on the success or failure of the corresponding request.
    • getError

      public JsonRpcError getError()
      Retrieves the error associated with the JSON-RPC response.
      Returns:
      the JsonRpcError object representing the error details, or null if the response does not contain an error.
    • setError

      public void setError(JsonRpcError error)
      Sets the error attribute of the JSON-RPC response.
      Parameters:
      error - the JsonRpcError object representing the error details associated with the response.
    • getId

      public Object 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

      public void setId(Object id)
      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.