]>
nmode's Git Repositories - signal-cli/blob - src/main/java/org/asamk/signal/jsonrpc/JsonRpcResponse.java
1 package org
.asamk
.signal
.jsonrpc
;
3 import com
.fasterxml
.jackson
.annotation
.JsonInclude
;
4 import com
.fasterxml
.jackson
.databind
.JsonNode
;
5 import com
.fasterxml
.jackson
.databind
.node
.ValueNode
;
8 * Represents a JSON-RPC response.
9 * https://www.jsonrpc.org/specification#response_object
11 public class JsonRpcResponse
extends JsonRpcMessage
{
14 * A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
19 * This member is REQUIRED on success.
20 * This member MUST NOT exist if there was an error invoking the method.
21 * The value of this member is determined by the method invoked on the Server.
23 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
27 * This member is REQUIRED on error.
28 * This member MUST NOT exist if there was no error triggered during invocation.
29 * The value for this member MUST be an Object as defined in section 5.1.
31 @JsonInclude(JsonInclude
.Include
.NON_NULL
)
35 * This member is REQUIRED.
36 * It MUST be the same as the value of the id member in the Request Object.
37 * If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.
41 public static JsonRpcResponse
forSuccess(JsonNode result
, ValueNode id
) {
42 return new JsonRpcResponse("2.0", result
, null, id
);
45 public static JsonRpcResponse
forError(Error error
, ValueNode id
) {
46 return new JsonRpcResponse("2.0", null, error
, id
);
49 private JsonRpcResponse() {
52 private JsonRpcResponse(final String jsonrpc
, final JsonNode result
, final Error error
, final ValueNode id
) {
53 this.jsonrpc
= jsonrpc
;
59 public String
getJsonrpc() {
63 public JsonNode
getResult() {
67 public Error
getError() {
71 public ValueNode
getId() {
75 public static class Error
{
77 public static final int PARSE_ERROR
= -32700;
78 public static final int INVALID_REQUEST
= -32600;
79 public static final int METHOD_NOT_FOUND
= -32601;
80 public static final int INVALID_PARAMS
= -32602;
81 public static final int INTERNAL_ERROR
= -32603;
84 * A Number that indicates the error type that occurred.
85 * This MUST be an integer.
90 * A String providing a short description of the error.
91 * The message SHOULD be limited to a concise single sentence.
96 * A Primitive or Structured value that contains additional information about the error.
97 * This may be omitted.
98 * The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).
102 public Error(final int code
, final String message
, final JsonNode data
) {
104 this.message
= message
;
108 public int getCode() {
112 public String
getMessage() {
116 public JsonNode
getData() {