Package org.starcoin.jsonrpc
Class JSONRPC2Request
- java.lang.Object
-
- org.starcoin.jsonrpc.JSONRPC2Request
-
public class JSONRPC2Request extends Object
Represents a JSON-RPC 2.0 request.A request carries four pieces of data:
methodThe name of the remote method to call.paramsThe required method parameters (if any), which can be packed into a JSON array or object.idAn identifier which is echoed back to the client with the response.jsonrpcA string indicating the JSON-RPC protocol version set to "2.0".
Here is a sample JSON-RPC 2.0 request string:
{ "method" : "makePayment", "params" : { "recipient" : "Penny Adams", "amount":175.05 }, "id" : "0001", "jsonrpc" : "2.0" }- Author:
- Vladimir Dzhuvinov
-
-
Constructor Summary
Constructors Constructor Description JSONRPC2Request(String method, Object id)Constructs a new JSON-RPC 2.0 request with no parameters.JSONRPC2Request(String method, List<Object> positionalParams, Object id)Constructs a new JSON-RPC 2.0 request with positional (JSON array) parameters.JSONRPC2Request(String method, Map<String,Object> namedParams, Object id)Constructs a new JSON-RPC 2.0 request with named (JSON object) parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ObjectgetID()Gets the request identifier.StringgetMethod()Gets the name of the requested method.Map<String,Object>getNamedParams()Gets the named parameters.ObjectgetParams()Gets the request parameters.JSONRPC2ParamsTypegetParamsType()List<Object>getPositionalParams()Gets the positional (JSON array) parameters.voidsetID(Object id)Sets the request identifier (ID).voidsetMethod(String method)Sets the name of the requested method.voidsetNamedParams(Map<String,Object> namedParams)Sets the named (JSON object) request parameters.voidsetParams(Object params)Deprecated.voidsetPositionalParams(List<Object> positionalParams)Sets the positional (JSON array) request parameters.StringtoString()
-
-
-
Constructor Detail
-
JSONRPC2Request
public JSONRPC2Request(String method, Object id)
Constructs a new JSON-RPC 2.0 request with no parameters.- Parameters:
method- The name of the requested method. Must not benull.id- The request identifier echoed back to the caller. The value must map to a JSON scalar (nulland fractions, however, should be avoided).
-
JSONRPC2Request
public JSONRPC2Request(String method, List<Object> positionalParams, Object id)
Constructs a new JSON-RPC 2.0 request with positional (JSON array) parameters.- Parameters:
method- The name of the requested method. Must not benull.positionalParams- The positional (JSON array) parameters,nullif none.id- The request identifier echoed back to the caller. The value must map to a JSON scalar (nulland fractions, however, should be avoided).
-
JSONRPC2Request
public JSONRPC2Request(String method, Map<String,Object> namedParams, Object id)
Constructs a new JSON-RPC 2.0 request with named (JSON object) parameters.- Parameters:
method- The name of the requested method.namedParams- The named (JSON object) parameters,nullif none.id- The request identifier echoed back to the caller. The value must map to a JSON scalar (nulland fractions, however, should be avoided).
-
-
Method Detail
-
getMethod
public String getMethod()
Gets the name of the requested method.- Returns:
- The method name.
-
setMethod
public void setMethod(String method)
Sets the name of the requested method.- Parameters:
method- The method name. Must not benull.
-
getParamsType
public JSONRPC2ParamsType getParamsType()
- Returns:
- The parameters type.
-
getParams
public Object getParams()
Gets the request parameters.This method was deprecated in version 1.30. Use
getPositionalParams()orgetNamedParams()instead.- Returns:
- The parameters as
List<Object>for positional (JSON array),Map<String,Object>for named (JSON object), ornullif none.
-
setParams
@Deprecated public void setParams(Object params)
Deprecated.Sets the request parameters.This method was deprecated in version 1.30. Use
setPositionalParams(java.util.List<java.lang.Object>)orsetNamedParams(java.util.Map<java.lang.String, java.lang.Object>)instead.- Parameters:
params- The parameters. For positional (JSON array) pass aList<Object>. For named (JSON object) pass aMap<String,Object>. If there are no parameters passnull.
-
getPositionalParams
public List<Object> getPositionalParams()
Gets the positional (JSON array) parameters.- Returns:
- The positional (JSON array) parameters,
nullif none or named. - Since:
- 1.30
-
setPositionalParams
public void setPositionalParams(List<Object> positionalParams)
Sets the positional (JSON array) request parameters.- Parameters:
positionalParams- The positional (JSON array) request parameters,nullif none.- Since:
- 1.30
-
getNamedParams
public Map<String,Object> getNamedParams()
Gets the named parameters.- Returns:
- The named (JSON object) parameters,
nullif none or positional. - Since:
- 1.30
-
setNamedParams
public void setNamedParams(Map<String,Object> namedParams)
Sets the named (JSON object) request parameters.- Parameters:
namedParams- The named (JSON object) request parameters,nullif none.- Since:
- 1.30
-
getID
public Object getID()
Gets the request identifier.- Returns:
- The request identifier (
Number,Boolean,String) ornull.
-
setID
public void setID(Object id)
Sets the request identifier (ID).- Parameters:
id- The request identifier echoed back to the caller. The value must map to a JSON scalar (nulland fractions, however, should be avoided).
-
-