Package eu.woolplatform.utils.json.rpc
Class JsonRpcResponse
- java.lang.Object
-
- eu.woolplatform.utils.json.rpc.JsonRpcMessage
-
- eu.woolplatform.utils.json.rpc.JsonRpcResponse
-
public class JsonRpcResponse extends JsonRpcMessage
This class models a JSON-RPC Response.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJsonRpcResponse.ErrorAn error in a response message.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static JsonRpcResponsecreateError(JsonRpcResponse.Error error, Object id)Creates a JSON-RPC response with an error.static JsonRpcResponsecreateResult(Object result, Object id)Creates a JSON-RPC response with a result.JsonRpcResponse.ErrorgetError()Returns the error, if this response contains an error.ObjectgetID()Returns the request ID (string, number or null).ObjectgetResult()Returns the result.static JsonRpcResponseread(Map<?,?> map)Reads a JSON-RPC response from the specified map, which should represent a JSON object.StringtoString()voidwrite(Writer out)Writes this message as a JSON string to the specified writer.
-
-
-
Method Detail
-
read
public static JsonRpcResponse read(Map<?,?> map) throws ParseException
Reads a JSON-RPC response from the specified map, which should represent a JSON object.- Parameters:
map- the map- Returns:
- the response
- Throws:
ParseException- if the map is not a valid JSON-RPC response- See Also:
JsonRpcMessage.read(Map)
-
createResult
public static JsonRpcResponse createResult(Object result, Object id)
Creates a JSON-RPC response with a result.- Parameters:
result- the resultid- the response ID (string, number or null)- Returns:
- the response
-
createError
public static JsonRpcResponse createError(JsonRpcResponse.Error error, Object id)
Creates a JSON-RPC response with an error.- Parameters:
error- the errorid- the response ID (string, number or null)- Returns:
- the response
-
getResult
public Object getResult()
Returns the result. If this response doesn't contain a result, this method returns null andgetError()should return an error.- Returns:
- the result or null
-
getError
public JsonRpcResponse.Error getError()
Returns the error, if this response contains an error. Otherwise it returns null andgetResult()should return a result.- Returns:
- the error or null
-
getID
public Object getID()
Returns the request ID (string, number or null).- Returns:
- the request ID (string, number or null)
-
write
public void write(Writer out) throws IOException
Description copied from class:JsonRpcMessageWrites this message as a JSON string to the specified writer.- Specified by:
writein classJsonRpcMessage- Parameters:
out- the writer- Throws:
IOException- if a writing error occurs
-
toString
public String toString()
- Overrides:
toStringin classJsonRpcMessage
-
-