Class Request
- java.lang.Object
-
- eliasstar.jsonrpc.objects.Request
-
- Direct Known Subclasses:
Notification
public class Request extends Object
Represents a JSON-RPC request.- Since:
- 0.1.0
- Author:
- Elias*
- See Also:
- JSON-RPC Specification
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Request(Id<?> id, String method, Parameters<?> params)
Creates aRequest
.Request(Number id, String method)
Creates aRequest
without parameters.Request(Number id, String method, com.google.gson.JsonArray params)
Creates aRequest
with parameters in array format.Request(Number id, String method, com.google.gson.JsonObject params)
Creates aRequest
with parameters in object format.Request(String id, String method)
Creates aRequest
without parameters.Request(String id, String method, com.google.gson.JsonArray params)
Creates aRequest
with parameters in array format.Request(String id, String method, com.google.gson.JsonObject params)
Creates aRequest
with parameters in object format.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
contentAsJsonString()
boolean
equals(Object obj)
This method returnstrue
if the argument is aRequest
and all properties are equal, otherwise returnsfalse
.int
hashCode()
This method is implemented usingObjects.hash()
.Optional<Id<?>>
id()
Getter for id field.String
jsonrpc()
Getter for jsonrpc field.String
method()
Getter for method field.Optional<Parameters<?>>
params()
Getter for params field.String
toString()
-
-
-
Constructor Detail
-
Request
protected Request(Id<?> id, String method, Parameters<?> params)
Creates aRequest
.- Parameters:
id
- If null theRequest
is considered to be aNotification
method
- Must not be nullparams
- If null theRequest
has no params
-
Request
public Request(String id, String method)
Creates aRequest
without parameters.If id is
null
the request id will be serialized as the JSONnull
value. If you want to omit the id, you should create aNotification
.- Parameters:
id
- A id of typeString
ornull
method
- The non-null method you want to invoke
-
Request
public Request(String id, String method, com.google.gson.JsonArray params)
Creates aRequest
with parameters in array format.If id is
null
the request id will be serialized as the JSONnull
value. If you want to omit the id you should create aNotification
.If params is null a NullPointerException will be thrown. If you want to create a request without parameters, you should use
Request(String, String)
- Parameters:
id
- A id of typeString
ornull
method
- The non-null method you want to invokeparams
- The parameters provided asJsonArray
-
Request
public Request(String id, String method, com.google.gson.JsonObject params)
Creates aRequest
with parameters in object format.If id is
null
the request id will be serialized as the JSONnull
value. If you want to omit the id you should create aNotification
.If params is null a NullPointerException will be thrown. If you want to create a request without parameters, you should use
Request(String, String)
- Parameters:
id
- A id of typeString
ornull
method
- The non-null method you want to invokeparams
- The parameters provided asJsonObject
-
Request
public Request(Number id, String method)
Creates aRequest
without parameters.If id is
null
the request id will be serialized as the JSONnull
value. If you want to omit the id, you should create aNotification
.- Parameters:
id
- A id of typeNumber
ornull
method
- The non-null method you want to invoke
-
Request
public Request(Number id, String method, com.google.gson.JsonArray params)
Creates aRequest
with parameters in array format.If id is
null
the request id will be serialized as the JSONnull
value. If you want to omit the id you should create aNotification
.If params is null a NullPointerException will be thrown. If you want to create a request without parameters, you should use
Request(Number, String)
- Parameters:
id
- A id of typeNumber
ornull
method
- The non-null method you want to invokeparams
- The parameters provided asJsonArray
-
Request
public Request(Number id, String method, com.google.gson.JsonObject params)
Creates aRequest
with parameters in object format.If id is
null
the request id will be serialized as the JSONnull
value. If you want to omit the id you should create aNotification
.If params is null a NullPointerException will be thrown. If you want to create a request without parameters, you should use
Request(Number, String)
- Parameters:
id
- A id of typeNumber
ornull
method
- The non-null method you want to invokeparams
- The parameters provided asJsonObject
-
-
Method Detail
-
jsonrpc
public String jsonrpc()
Getter for jsonrpc field.It is always
"2.0"
.- Returns:
- The version of the JSON-RPC protocol
-
id
public Optional<Id<?>> id()
Getter for id field.If the
Optional
is empty theRequest
is considered to be aNotification
.- Returns:
- The id of this
Request
-
method
public String method()
Getter for method field.- Returns:
- The name of the method to be invoked
-
params
public Optional<Parameters<?>> params()
Getter for params field.- Returns:
- The parameters of this
Request
-
hashCode
public int hashCode()
This method is implemented usingObjects.hash()
.
-
equals
public boolean equals(Object obj)
This method returnstrue
if the argument is aRequest
and all properties are equal, otherwise returnsfalse
.
-
toString
public String toString()
-
-