|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.thetransactioncompany.jsonrpc2.JSONRPC2Message
public abstract class JSONRPC2Message
The base abstract class for JSON-RPC 2.0 requests, notifications and responses. Provides generic methods for parsing (from JSON string) and serialisation (to JSON string) of the three message types.
Example showing parsing and serialisation back to JSON:
String jsonString = "{\"method\":\"progressNotify\",\"params\":[\"75%\"],\"jsonrpc\":\"2.0\"}";
JSONRPC2Message message = null;
// parse
try {
message = JSONRPC2Message.parse(jsonString);
} catch (JSONRPC2ParseException e) {
// handle parse error
}
if (message instanceof JSONRPC2Request)
System.out.println("The message is a request");
else if (message instanceof JSONRPC2Notification)
System.out.println("The message is a notification");
else if (message instanceof JSONRPC2Response)
System.out.println("The message is a response");
// serialise back to JSON string
System.out.println(message);
The mapping between JSON and Java entities (as defined by the underlying JSON.simple library):
true|false <---> java.lang.Boolean
number <---> java.lang.Number
string <---> java.lang.String
array <---> java.util.List
object <---> java.util.Map
null <---> null
The JSON-RPC 2.0 specification and user group forum can be found here.
| Constructor Summary | |
|---|---|
JSONRPC2Message()
|
|
| Method Summary | |
|---|---|
static JSONRPC2Message |
parse(java.lang.String jsonString)
Provides common parsing of JSON-RPC 2.0 requests, notifications and responses. |
abstract org.json.simple.JSONObject |
toJSON()
Gets a JSON object representing the message. |
java.lang.String |
toString()
Serialises the message to a JSON string. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public JSONRPC2Message()
| Method Detail |
|---|
public static JSONRPC2Message parse(java.lang.String jsonString)
throws JSONRPC2ParseException
If you are certain about the message type use the dedicated
JSONRPC2Request.parse(java.lang.String), JSONRPC2Notification.parse(java.lang.String)
and JSONRPC2Response.parse(java.lang.String) methods. They are more efficient
and would provide you with better parse error reporting.
jsonString - A JSON string representing a JSON-RPC 2.0 request,
notification or response.
JSONRPC2Request,
JSONRPC2Notification or JSONRPC2Response.
JSONRPC2ParseException - With detailed message if the parsing
failed.public abstract org.json.simple.JSONObject toJSON()
public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||