Class JsonRpcResponse

java.lang.Object
org.apache.juneau.bean.jsonrpc.JsonRpcResponse

@Marshalled public class JsonRpcResponse extends Object
JSON-RPC 2.0 success or error response envelope.

Exactly one of result or error should be present for a valid response.

This envelope is generic JSON-RPC 2.0 and carries no _meta property: MCP-specific per-result metadata belongs under result._meta, not beside the envelope. See the 2026-07-28 v2 bean package (org.apache.juneau.bean.mcp.v20260728) for the typed nested carrier.

  • Constructor Details

  • Method Details

    • getJsonrpc

      public String getJsonrpc()
      JSON-RPC protocol version.
      Returns:
      The version token, or null if not set.
    • setJsonrpc

      Sets the JSON-RPC protocol version.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object (for method chaining).
    • getId

      public Object getId()
      Correlates to the request id.
      Returns:
      The id, or null if not set.
    • setId

      public JsonRpcResponse setId(Object value)
      Sets the response id.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object (for method chaining).
    • getResult

      public Object getResult()
      Result payload on success.
      Returns:
      The result, or null if not set.
    • setResult

      Sets the result payload.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object (for method chaining).
    • getError

      Error payload on failure.
      Returns:
      The error, or null if not set.
    • setError

      Sets the error payload.
      Parameters:
      value - The new value. Can be null to unset the property.
      Returns:
      This object (for method chaining).
    • notification

      public static boolean notification(Object id)
      Tests whether a JSON-RPC id identifies a notification (a request that must not be answered).

      A JSON-RPC request with no id is a notification; the server performs the work and returns no response body.

      Parameters:
      id - The request id. Can be null.
      Returns:
      true if the id is null.
    • ok

      public static JsonRpcResponse ok(Object id, Object result)
      Creates a JSON-RPC 2.0 success response.
      Parameters:
      id - The request id to correlate against. Can be null.
      result - The result payload. Can be null.
      Returns:
      A new response object. Never null.
    • errorResponse

      public static JsonRpcResponse errorResponse(Object id, int code, String message)
      Creates a JSON-RPC 2.0 error response with no structured error data.
      Parameters:
      id - The request id to correlate against. Can be null.
      code - The JSON-RPC error code.
      message - The error message. Can be null.
      Returns:
      A new response object. Never null.
    • errorResponse

      public static JsonRpcResponse errorResponse(Object id, int code, String message, Object data)
      Creates a JSON-RPC 2.0 error response.
      Parameters:
      id - The request id to correlate against. Can be null.
      code - The JSON-RPC error code.
      message - The error message. Can be null.
      data - Optional structured error data. Can be null to leave the property unset.
      Returns:
      A new response object. Never null.