1 package org.asamk.signal.jsonrpc; 2 3 import com.fasterxml.jackson.annotation.JsonInclude; 4 import com.fasterxml.jackson.databind.node.ContainerNode; 5 import com.fasterxml.jackson.databind.node.ValueNode; 6 7 /** 8 * Represents a JSON-RPC request. 9 * https://www.jsonrpc.org/specification#request_object 10 */ 11 public class JsonRpcRequest extends JsonRpcMessage { 12 13 /** 14 * A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0". 15 */ 16 String jsonrpc; 17 18 /** 19 * A String containing the name of the method to be invoked. 20 * Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46) 21 * are reserved for rpc-internal methods and extensions and MUST NOT be used for anything else. 22 */ 23 String method; 24 25 /** 26 * A Structured value that holds the parameter values to be used during the invocation of the method. 27 * This member MAY be omitted. 28 */ 29 @JsonInclude(JsonInclude.Include.NON_NULL) 30 ContainerNode<?> params; 31 32 /** 33 * An identifier established by the Client that MUST contain a String, Number, or NULL value if included. 34 * If it is not included it is assumed to be a notification. 35 * The value SHOULD normally not be Null and Numbers SHOULD NOT contain fractional parts 36 */ 37 @JsonInclude(JsonInclude.Include.NON_NULL) 38 ValueNode id; 39 forNotification( final String method, final ContainerNode<?> params, final ValueNode id )40 public static JsonRpcRequest forNotification( 41 final String method, final ContainerNode<?> params, final ValueNode id 42 ) { 43 return new JsonRpcRequest("2.0", method, params, id); 44 } 45 JsonRpcRequest()46 private JsonRpcRequest() { 47 } 48 JsonRpcRequest( final String jsonrpc, final String method, final ContainerNode<?> params, final ValueNode id )49 private JsonRpcRequest( 50 final String jsonrpc, final String method, final ContainerNode<?> params, final ValueNode id 51 ) { 52 this.jsonrpc = jsonrpc; 53 this.method = method; 54 this.params = params; 55 this.id = id; 56 } 57 getJsonrpc()58 public String getJsonrpc() { 59 return jsonrpc; 60 } 61 getMethod()62 public String getMethod() { 63 return method; 64 } 65 getParams()66 public ContainerNode<?> getParams() { 67 return params; 68 } 69 getId()70 public ValueNode getId() { 71 return id; 72 } 73 } 74