Class MessageJsonHandler


  • public class MessageJsonHandler
    extends java.lang.Object
    A wrapper around Gson that includes configuration required for JSON-RPC messages.
    • Field Detail

    • Constructor Detail

      • MessageJsonHandler

        public MessageJsonHandler​(java.util.Map<java.lang.String,​JsonRpcMethod> supportedMethods)
        Parameters:
        supportedMethods - - a map used to resolve RPC methods in getJsonRpcMethod(String)
      • MessageJsonHandler

        public MessageJsonHandler​(java.util.Map<java.lang.String,​JsonRpcMethod> supportedMethods,
                                  java.util.function.Consumer<com.google.gson.GsonBuilder> configureGson)
        Parameters:
        supportedMethods - - a map used to resolve RPC methods in getJsonRpcMethod(String)
        configureGson - - a function that contributes to the GsonBuilder created by getDefaultGsonBuilder()
    • Method Detail

      • getDefaultGsonBuilder

        public com.google.gson.GsonBuilder getDefaultGsonBuilder()
        Create a GsonBuilder with default settings for parsing JSON-RPC messages.
      • getGson

        public com.google.gson.Gson getGson()
      • getJsonRpcMethod

        public JsonRpcMethod getJsonRpcMethod​(java.lang.String name)
        Resolve an RPC method by name.
      • setMethodProvider

        public void setMethodProvider​(MethodProvider methodProvider)
      • parseMessage

        public Message parseMessage​(java.lang.CharSequence input)
                             throws com.google.gson.JsonParseException
        Throws:
        com.google.gson.JsonParseException
      • parseMessage

        public Message parseMessage​(java.io.Reader input)
                             throws com.google.gson.JsonParseException
        Throws:
        com.google.gson.JsonParseException
      • serialize

        public java.lang.String serialize​(Message message)
      • serialize

        public void serialize​(Message message,
                              java.io.Writer output)
                       throws com.google.gson.JsonIOException
        Throws:
        com.google.gson.JsonIOException
      • format

        public java.lang.String format​(java.lang.Object object)
        Perform JSON serialization of the given object using the configuration of JSON-RPC messages enhanced with the pretty printing option.
      • toString

        public static java.lang.String toString​(java.lang.Object object)
        Perform JSON serialization of the given object using the default configuration of JSON-RPC messages enhanced with the pretty printing option.