Class NamedParamsRetriever


  • public class NamedParamsRetriever
    extends ParamsRetriever
    Utility class for retrieving JSON-RPC 2.0 named parameters (key-value pairs packed into a JSON Object).

    Provides a set of getter methods according to the expected parameter type (number, string, etc.) and whether the parameter is mandatory or optional:

    • getXXX(param_name) for mandatory parameters, where XXX is the expected parameter type.
    • getOptXXX(param_name, default_value) for optional parameters, specifying a default value.

    There are also generic getter methods that let you do the type conversion yourself.

    If a parameter cannot be retrieved, e.g. due to a missing mandatory parameter or bad type, a JSONRPC2Error.INVALID_PARAMS exception is thrown.

    Example: suppose you have a method with 3 named parameters "name", "age" and "sex", where the last is optional and defaults to "female":

     // Parse received request string
     JSONRPC2Request request = null;
    
     try {
             request = JSONRPC2Request.parse(jsonString);
     } catch (JSONRPC2ParseException e) {
             // handle exception...
     }
    
     // Create a new retriever for named parameters
     Map params = (Map)request.getParams();
     NamedParamsRetriever r = new NamedParamsRetriever(params);
    
     try {
             // Extract "name" string parameter
             String name = r.getString("name");
    
             // Extract "age" integer parameter
             int age = r.getInt("age");
    
             // Extract optional "sex" string parameter which defaults to "female"
             String sex = r.getOptString("sex", "female");
    
     } catch (JSONRPC2Error e) {
             // A JSONRPC2Error.INVALID_PARAMS will be thrown to indicate
             // an unexpected parameter type or a missing mandatory parameter.
             // You can use it straight away to create the appropriate
             // JSON-RPC 2.0 error response.
             JSONRPC2Response response = new JSONRPC2Response(e, null);
     }
     
     
    Author:
    Vladimir Dzhuvinov
    • Constructor Summary

      Constructors 
      Constructor Description
      NamedParamsRetriever​(java.util.Map<java.lang.String,​java.lang.Object> params)
      Creates a new named parameters retriever from the specified key-value map.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void ensureParam​(java.lang.String name)
      Throws a JSONRPC2Error.INVALID_PARAMS exception if there is no parameter by the specified name.
      <T> void ensureParam​(java.lang.String name, java.lang.Class<T> clazz)
      Throws a JSONRPC2Error.INVALID_PARAMS exception if there is no parameter by the specified name, its value is null, or its type doesn't map to the specified.
      <T> void ensureParam​(java.lang.String name, java.lang.Class<T> clazz, boolean allowNull)
      Throws a JSONRPC2Error.INVALID_PARAMS exception if there is no parameter by the specified name or its type doesn't map to the specified.
      void ensureParams​(java.lang.String[] mandatoryNames)
      Throws a JSONRPC2Error.INVALID_PARAMS if the specified names aren't present in the parameters, or names outside the specified are contained.
      void ensureParams​(java.lang.String[] mandatoryNames, java.lang.String[] optionalNames)
      Throws a JSONRPC2Error.INVALID_PARAMS if the specified mandatory names aren't contained in the parameters, or names outside the specified mandatory and optional are present.
      java.lang.Object get​(java.lang.String name)
      Retrieves the specified parameter which can be of any type.
      <T> T get​(java.lang.String name, java.lang.Class<T> clazz)
      Retrieves the specified parameter which must map to the provided class (use the appropriate wrapper class for primitive types).
      <T> T get​(java.lang.String name, java.lang.Class<T> clazz, boolean allowNull)
      Retrieves the specified parameter which must map to the provided class (use the appropriate wrapper class for primitive types).
      boolean getBoolean​(java.lang.String name)
      Retrieves the specified boolean (maps from JSON true/false) parameter.
      double getDouble​(java.lang.String name)
      Retrieves the specified numeric parameter as a double.
      <T extends java.lang.Enum<T>>
      T
      getEnum​(java.lang.String name, java.lang.Class<T> enumClass)
      Retrieves the specified enumerated parameter (from a JSON string that has a predefined set of possible values).
      <T extends java.lang.Enum<T>>
      T
      getEnum​(java.lang.String name, java.lang.Class<T> enumClass, boolean ignoreCase)
      Retrieves the specified enumerated parameter (from a JSON string that has a predefined set of possible values), allowing for a case insensitive match.
      java.lang.String getEnumString​(java.lang.String name, java.lang.String[] enumStrings)
      Retrieves the specified enumerated string parameter.
      java.lang.String getEnumString​(java.lang.String name, java.lang.String[] enumStrings, boolean ignoreCase)
      Retrieves the specified enumerated string parameter, allowing for a case insenstive match.
      float getFloat​(java.lang.String name)
      Retrieves the specified numeric parameter as a float.
      int getInt​(java.lang.String name)
      Retrieves the specified numeric parameter as an int.
      java.util.List<java.lang.Object> getList​(java.lang.String name)
      Retrieves the specified list (maps from JSON array) parameter.
      java.util.List<java.lang.Object> getList​(java.lang.String name, boolean allowNull)
      Retrieves the specified list (maps from JSON array) parameter.
      long getLong​(java.lang.String name)
      Retrieves the specified numeric parameter as a long.
      java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String name)
      Retrieves the specified map (maps from JSON object) parameter.
      java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String name, boolean allowNull)
      Retrieves the specified map (maps from JSON object) parameter.
      java.lang.String[] getNames()
      Returns the names of all available parameters.
      <T> T getOpt​(java.lang.String name, java.lang.Class<T> clazz, boolean allowNull, T defaultValue)
      Retrieves the specified optional parameter which must map to the provided class (use the appropriate wrapper class for primitive types).
      <T> T getOpt​(java.lang.String name, java.lang.Class<T> clazz, T defaultValue)
      Retrieves the specified optional parameter which must map to the provided class (use the appropriate wrapper class for primitive types).
      boolean getOptBoolean​(java.lang.String name, boolean defaultValue)
      Retrieves the specified optional boolean (maps from JSON true/false) parameter.
      double getOptDouble​(java.lang.String name, double defaultValue)
      Retrieves the specified optional numeric parameter as a double.
      <T extends java.lang.Enum<T>>
      T
      getOptEnum​(java.lang.String name, java.lang.Class<T> enumClass, T defaultValue)
      Retrieves the specified optional enumerated parameter (from a JSON string that has a predefined set of possible values).
      <T extends java.lang.Enum<T>>
      T
      getOptEnum​(java.lang.String name, java.lang.Class<T> enumClass, T defaultValue, boolean ignoreCase)
      Retrieves the specified optional enumerated parameter (from a JSON string that has a predefined set of possible values), allowing for a case-insensitive match.
      java.lang.String getOptEnumString​(java.lang.String name, java.lang.String[] enumStrings, java.lang.String defaultValue)
      Retrieves the specified optional enumerated string parameter.
      java.lang.String getOptEnumString​(java.lang.String name, java.lang.String[] enumStrings, java.lang.String defaultValue, boolean ignoreCase)
      Retrieves the specified optional enumerated string parameter, allowing for a case insenstive match.
      float getOptFloat​(java.lang.String name, float defaultValue)
      Retrieves the specified optional numeric parameter as a float.
      int getOptInt​(java.lang.String name, int defaultValue)
      Retrieves the specified optional numeric parameter as an int.
      java.util.List<java.lang.Object> getOptList​(java.lang.String name, boolean allowNull, java.util.List<java.lang.Object> defaultValue)
      Retrieves the specified optional list (maps from JSON array) parameter.
      java.util.List<java.lang.Object> getOptList​(java.lang.String name, java.util.List<java.lang.Object> defaultValue)
      Retrieves the specified optional list (maps from JSON array) parameter.
      long getOptLong​(java.lang.String name, long defaultValue)
      Retrieves the specified optional numeric parameter as a long.
      java.util.Map<java.lang.String,​java.lang.Object> getOptMap​(java.lang.String name, boolean allowNull, java.util.Map<java.lang.String,​java.lang.Object> defaultValue)
      Retrieves the specified optional map (maps from JSON object) parameter.
      java.util.Map<java.lang.String,​java.lang.Object> getOptMap​(java.lang.String name, java.util.Map<java.lang.String,​java.lang.Object> defaultValue)
      Retrieves the specified optional map (maps from JSON object) parameter.
      java.lang.String getOptString​(java.lang.String name, boolean allowNull, java.lang.String defaultValue)
      Retrieves the specified optional string parameter.
      java.lang.String getOptString​(java.lang.String name, java.lang.String defaultValue)
      Retrieves the specified optional string parameter.
      java.lang.String[] getOptStringArray​(java.lang.String name, boolean allowNull, java.lang.String[] defaultValue)
      Retrieves the specified optional string array (maps from JSON array of strings) parameter.
      java.lang.String[] getOptStringArray​(java.lang.String name, java.lang.String[] defaultValue)
      Retrieves the specified optional string array (maps from JSON array of strings) parameter.
      java.util.Map<java.lang.String,​java.lang.Object> getParams()
      Gets the named parameters for this retriever.
      java.lang.String getString​(java.lang.String name)
      Retrieves the specified string parameter.
      java.lang.String getString​(java.lang.String name, boolean allowNull)
      Retrieves the specified string parameter.
      java.lang.String[] getStringArray​(java.lang.String name)
      Retrieves the specified string array (maps from JSON array of strings) parameter.
      java.lang.String[] getStringArray​(java.lang.String name, boolean allowNull)
      Retrieves the specified string array (maps from JSON array of strings) parameter.
      boolean hasParam​(java.lang.String name)
      Returns true if a parameter by the specified name exists, else false.
      boolean hasParams​(java.lang.String[] names)
      Returns true if the parameters by the specified names exist, else false.
      boolean hasParams​(java.lang.String[] mandatoryNames, java.lang.String[] optionalNames)
      Returns true if the parameters by the specified mandatory names exist, false if any mandatory name is missing or a name outside the mandatory and optional is present.
      int size()
      Returns the parameter count.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • NamedParamsRetriever

        public NamedParamsRetriever​(java.util.Map<java.lang.String,​java.lang.Object> params)
        Creates a new named parameters retriever from the specified key-value map.
        Parameters:
        params - The named parameters map. Must not be null.
    • Method Detail

      • getParams

        public java.util.Map<java.lang.String,​java.lang.Object> getParams()
        Gets the named parameters for this retriever.
        Returns:
        The named parameters.
      • hasParam

        public boolean hasParam​(java.lang.String name)
        Returns true if a parameter by the specified name exists, else false.
        Parameters:
        name - The parameter name.
        Returns:
        true if the parameter exists, else false.
      • hasParams

        public boolean hasParams​(java.lang.String[] names)
        Returns true if the parameters by the specified names exist, else false.
        Parameters:
        names - The parameter names. Must not be null.
        Returns:
        true if the parameters exist, else false.
      • hasParams

        public boolean hasParams​(java.lang.String[] mandatoryNames,
                                 java.lang.String[] optionalNames)
        Returns true if the parameters by the specified mandatory names exist, false if any mandatory name is missing or a name outside the mandatory and optional is present.
        Parameters:
        mandatoryNames - The expected mandatory parameter names. Must not be null.
        optionalNames - The expected optional parameter names, empty array or null if none.
        Returns:
        true if the specified mandatory names and only any of the optional are present, else false.
      • getNames

        public java.lang.String[] getNames()
        Returns the names of all available parameters.
        Returns:
        The parameter names.
      • ensureParams

        public void ensureParams​(java.lang.String[] mandatoryNames)
                          throws JSONRPC2Error
        Throws a JSONRPC2Error.INVALID_PARAMS if the specified names aren't present in the parameters, or names outside the specified are contained.

        You may use this method to a fire a proper JSON-RPC 2.0 error on a missing or unexpected mandatory parameter name.

        Parameters:
        mandatoryNames - The expected parameter names. Must not be null.
        Throws:
        JSONRPC2Error - On a missing parameter name or names outside the specified (JSONRPC2Error.INVALID_PARAMS).
      • ensureParams

        public void ensureParams​(java.lang.String[] mandatoryNames,
                                 java.lang.String[] optionalNames)
                          throws JSONRPC2Error
        Throws a JSONRPC2Error.INVALID_PARAMS if the specified mandatory names aren't contained in the parameters, or names outside the specified mandatory and optional are present.

        You may use this method to a fire a proper JSON-RPC 2.0 error on a missing or unexpected mandatory parameter name.

        Parameters:
        mandatoryNames - The expected mandatory parameter names. Must not be null.
        optionalNames - The expected optional parameter names, empty array or null if none.
        Throws:
        JSONRPC2Error - On a missing mandatory parameter name or names outside the specified mandatory and optional (JSONRPC2Error.INVALID_PARAMS).
      • ensureParam

        public void ensureParam​(java.lang.String name)
                         throws JSONRPC2Error
        Throws a JSONRPC2Error.INVALID_PARAMS exception if there is no parameter by the specified name.

        You may use this method to fire the proper JSON-RPC 2.0 error on a missing mandatory parameter.

        Parameters:
        name - The parameter name.
        Throws:
        JSONRPC2Error - On a missing parameter (JSONRPC2Error.INVALID_PARAMS).
      • ensureParam

        public <T> void ensureParam​(java.lang.String name,
                                    java.lang.Class<T> clazz)
                             throws JSONRPC2Error
        Throws a JSONRPC2Error.INVALID_PARAMS exception if there is no parameter by the specified name, its value is null, or its type doesn't map to the specified.

        You may use this method to fire the proper JSON-RPC 2.0 error on a missing or badly-typed mandatory parameter.

        Parameters:
        name - The parameter name.
        clazz - The corresponding Java class that the parameter should map to (any one of the return types of the getXXX() getter methods. Set to Object.class to allow any type. Must not be null.
        Throws:
        JSONRPC2Error - On a missing parameter, null value or bad type (JSONRPC2Error.INVALID_PARAMS).
      • ensureParam

        public <T> void ensureParam​(java.lang.String name,
                                    java.lang.Class<T> clazz,
                                    boolean allowNull)
                             throws JSONRPC2Error
        Throws a JSONRPC2Error.INVALID_PARAMS exception if there is no parameter by the specified name or its type doesn't map to the specified.

        You may use this method to fire the proper JSON-RPC 2.0 error on a missing or badly-typed mandatory parameter.

        Parameters:
        name - The parameter name.
        clazz - The corresponding Java class that the parameter should map to (any one of the return types of the getXXX() getter methods. Set to Object.class to allow any type. Must not be null.
        allowNull - If true allows a null parameter value.
        Throws:
        JSONRPC2Error - On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
      • get

        public java.lang.Object get​(java.lang.String name)
                             throws JSONRPC2Error
        Retrieves the specified parameter which can be of any type. Use this generic getter if you want to cast the value yourself. Otherwise look at the typed get* methods.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value.
        Throws:
        JSONRPC2Error - On a missing parameter (JSONRPC2Error.INVALID_PARAMS).
      • get

        public <T> T get​(java.lang.String name,
                         java.lang.Class<T> clazz)
                  throws JSONRPC2Error
        Retrieves the specified parameter which must map to the provided class (use the appropriate wrapper class for primitive types).
        Parameters:
        name - The parameter name.
        clazz - The corresponding Java class that the parameter should map to (any one of the return types of the getXXX() getter methods. Set to Object.class to allow any type. Must not be null.
        Returns:
        The parameter value.
        Throws:
        JSONRPC2Error - On a missing parameter, null value or bad type (JSONRPC2Error.INVALID_PARAMS).
      • get

        public <T> T get​(java.lang.String name,
                         java.lang.Class<T> clazz,
                         boolean allowNull)
                  throws JSONRPC2Error
        Retrieves the specified parameter which must map to the provided class (use the appropriate wrapper class for primitive types).
        Parameters:
        name - The parameter name.
        clazz - The corresponding Java class that the parameter should map to (any one of the return types of the getXXX() getter methods. Set to Object.class to allow any type. Must not be null.
        allowNull - If true allows a null parameter value.
        Returns:
        The parameter value.
        Throws:
        JSONRPC2Error - On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
      • getOpt

        public <T> T getOpt​(java.lang.String name,
                            java.lang.Class<T> clazz,
                            T defaultValue)
                     throws JSONRPC2Error
        Retrieves the specified optional parameter which must map to the provided class (use the appropriate wrapper class for primitive types). If the parameter doesn't exist the method returns the specified default value.
        Parameters:
        name - The parameter name.
        clazz - The corresponding Java class that the parameter should map to (any one of the return types of the getXXX() getter methods. Set to Object.class to allow any type. Must not be null.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value.
        Throws:
        JSONRPC2Error - On a bad parameter type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOpt

        public <T> T getOpt​(java.lang.String name,
                            java.lang.Class<T> clazz,
                            boolean allowNull,
                            T defaultValue)
                     throws JSONRPC2Error
        Retrieves the specified optional parameter which must map to the provided class (use the appropriate wrapper class for primitive types). If the parameter doesn't exist the method returns the specified default value.
        Parameters:
        name - The parameter name.
        clazz - The corresponding Java class that the parameter should map to (any one of the return types of the getXXX() getter methods. Set to Object.class to allow any type. Must not be null.
        allowNull - If true allows a null parameter value.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value.
        Throws:
        JSONRPC2Error - On a bad parameter type (JSONRPC2Error.INVALID_PARAMS).
      • getString

        public java.lang.String getString​(java.lang.String name)
                                   throws JSONRPC2Error
        Retrieves the specified string parameter.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value as a string.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getString

        public java.lang.String getString​(java.lang.String name,
                                          boolean allowNull)
                                   throws JSONRPC2Error
        Retrieves the specified string parameter.
        Parameters:
        name - The parameter name.
        allowNull - If true allows a null value.
        Returns:
        The parameter value as a string.
        Throws:
        JSONRPC2Error - On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
      • getOptString

        public java.lang.String getOptString​(java.lang.String name,
                                             java.lang.String defaultValue)
                                      throws JSONRPC2Error
        Retrieves the specified optional string parameter. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value as a string.
        Throws:
        JSONRPC2Error - On a bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOptString

        public java.lang.String getOptString​(java.lang.String name,
                                             boolean allowNull,
                                             java.lang.String defaultValue)
                                      throws JSONRPC2Error
        Retrieves the specified optional string parameter. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        allowNull - If true allows a null value.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value as a string.
        Throws:
        JSONRPC2Error - On a bad type (JSONRPC2Error.INVALID_PARAMS).
      • getEnumString

        public java.lang.String getEnumString​(java.lang.String name,
                                              java.lang.String[] enumStrings)
                                       throws JSONRPC2Error
        Retrieves the specified enumerated string parameter.
        Parameters:
        name - The parameter name.
        enumStrings - The acceptable string values. Must not be null.
        Returns:
        The parameter value as a string.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
      • getEnumString

        public java.lang.String getEnumString​(java.lang.String name,
                                              java.lang.String[] enumStrings,
                                              boolean ignoreCase)
                                       throws JSONRPC2Error
        Retrieves the specified enumerated string parameter, allowing for a case insenstive match.
        Parameters:
        name - The parameter name.
        enumStrings - The acceptable string values. Must not be null.
        ignoreCase - true for a case insensitive match.
        Returns:
        The matching parameter value as a string.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
      • getOptEnumString

        public java.lang.String getOptEnumString​(java.lang.String name,
                                                 java.lang.String[] enumStrings,
                                                 java.lang.String defaultValue)
                                          throws JSONRPC2Error
        Retrieves the specified optional enumerated string parameter.
        Parameters:
        name - The parameter name.
        enumStrings - The acceptable string values. Must not be null.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value as a string.
        Throws:
        JSONRPC2Error - On a bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
      • getOptEnumString

        public java.lang.String getOptEnumString​(java.lang.String name,
                                                 java.lang.String[] enumStrings,
                                                 java.lang.String defaultValue,
                                                 boolean ignoreCase)
                                          throws JSONRPC2Error
        Retrieves the specified optional enumerated string parameter, allowing for a case insenstive match. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        enumStrings - The acceptable string values. Must not be null.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        ignoreCase - true for a case insensitive match.
        Returns:
        The matching parameter value as a string.
        Throws:
        JSONRPC2Error - On a bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
      • getEnum

        public <T extends java.lang.Enum<T>> T getEnum​(java.lang.String name,
                                                       java.lang.Class<T> enumClass)
                                                throws JSONRPC2Error
        Retrieves the specified enumerated parameter (from a JSON string that has a predefined set of possible values).
        Parameters:
        name - The parameter name.
        enumClass - An enumeration type with constant names representing the acceptable string values. Must not be null.
        Returns:
        The matching enumeration constant.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
      • getEnum

        public <T extends java.lang.Enum<T>> T getEnum​(java.lang.String name,
                                                       java.lang.Class<T> enumClass,
                                                       boolean ignoreCase)
                                                throws JSONRPC2Error
        Retrieves the specified enumerated parameter (from a JSON string that has a predefined set of possible values), allowing for a case insensitive match.
        Parameters:
        name - The parameter name.
        enumClass - An enumeration type with constant names representing the acceptable string values. Must not be null.
        ignoreCase - If true a case insensitive match against the acceptable constant names is performed.
        Returns:
        The matching enumeration constant.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
      • getOptEnum

        public <T extends java.lang.Enum<T>> T getOptEnum​(java.lang.String name,
                                                          java.lang.Class<T> enumClass,
                                                          T defaultValue)
                                                   throws JSONRPC2Error
        Retrieves the specified optional enumerated parameter (from a JSON string that has a predefined set of possible values).
        Parameters:
        name - The parameter name.
        enumClass - An enumeration type with constant names representing the acceptable string values. Must not be null.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The matching enumeration constant.
        Throws:
        JSONRPC2Error - On a bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
      • getOptEnum

        public <T extends java.lang.Enum<T>> T getOptEnum​(java.lang.String name,
                                                          java.lang.Class<T> enumClass,
                                                          T defaultValue,
                                                          boolean ignoreCase)
                                                   throws JSONRPC2Error
        Retrieves the specified optional enumerated parameter (from a JSON string that has a predefined set of possible values), allowing for a case-insensitive match. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        enumClass - An enumeration type with constant names representing the acceptable string values. Must not be null.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        ignoreCase - If true a case insensitive match against the acceptable constant names is performed.
        Returns:
        The matching enumeration constant.
        Throws:
        JSONRPC2Error - On a bad type or bad enumeration value (JSONRPC2Error.INVALID_PARAMS).
      • getBoolean

        public boolean getBoolean​(java.lang.String name)
                           throws JSONRPC2Error
        Retrieves the specified boolean (maps from JSON true/false) parameter.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value as a boolean.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOptBoolean

        public boolean getOptBoolean​(java.lang.String name,
                                     boolean defaultValue)
                              throws JSONRPC2Error
        Retrieves the specified optional boolean (maps from JSON true/false) parameter. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        defaultValue - The default return value if the parameter doesn't exist.
        Returns:
        The parameter value as a boolean.
        Throws:
        JSONRPC2Error - On a bad parameter type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getInt

        public int getInt​(java.lang.String name)
                   throws JSONRPC2Error
        Retrieves the specified numeric parameter as an int.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value as an int.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOptInt

        public int getOptInt​(java.lang.String name,
                             int defaultValue)
                      throws JSONRPC2Error
        Retrieves the specified optional numeric parameter as an int. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        defaultValue - The default return value if the parameter doesn't exist.
        Returns:
        The parameter value as an int.
        Throws:
        JSONRPC2Error - On a bad parameter type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getLong

        public long getLong​(java.lang.String name)
                     throws JSONRPC2Error
        Retrieves the specified numeric parameter as a long.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value as a long.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOptLong

        public long getOptLong​(java.lang.String name,
                               long defaultValue)
                        throws JSONRPC2Error
        Retrieves the specified optional numeric parameter as a long. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        defaultValue - The default return value if the parameter doesn't exist.
        Returns:
        The parameter value as a long.
        Throws:
        JSONRPC2Error - On a bad parameter type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getFloat

        public float getFloat​(java.lang.String name)
                       throws JSONRPC2Error
        Retrieves the specified numeric parameter as a float.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value as a float.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOptFloat

        public float getOptFloat​(java.lang.String name,
                                 float defaultValue)
                          throws JSONRPC2Error
        Retrieves the specified optional numeric parameter as a float. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        defaultValue - The default return value if the parameter doesn't exist.
        Returns:
        The parameter value as a float.
        Throws:
        JSONRPC2Error - On a bad parameter type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getDouble

        public double getDouble​(java.lang.String name)
                         throws JSONRPC2Error
        Retrieves the specified numeric parameter as a double.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value as a double.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOptDouble

        public double getOptDouble​(java.lang.String name,
                                   double defaultValue)
                            throws JSONRPC2Error
        Retrieves the specified optional numeric parameter as a double. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        defaultValue - The default return value if the parameter doesn't exist.
        Returns:
        The parameter value as a double.
        Throws:
        JSONRPC2Error - On a bad parameter type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getList

        public java.util.List<java.lang.Object> getList​(java.lang.String name)
                                                 throws JSONRPC2Error
        Retrieves the specified list (maps from JSON array) parameter.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value as a list.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getList

        public java.util.List<java.lang.Object> getList​(java.lang.String name,
                                                        boolean allowNull)
                                                 throws JSONRPC2Error
        Retrieves the specified list (maps from JSON array) parameter.
        Parameters:
        name - The parameter name.
        allowNull - If true allows a null value.
        Returns:
        The parameter value as a list.
        Throws:
        JSONRPC2Error - On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
      • getOptList

        public java.util.List<java.lang.Object> getOptList​(java.lang.String name,
                                                           java.util.List<java.lang.Object> defaultValue)
                                                    throws JSONRPC2Error
        Retrieves the specified optional list (maps from JSON array) parameter. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value as a list.
        Throws:
        JSONRPC2Error - On a bad parameter type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOptList

        public java.util.List<java.lang.Object> getOptList​(java.lang.String name,
                                                           boolean allowNull,
                                                           java.util.List<java.lang.Object> defaultValue)
                                                    throws JSONRPC2Error
        Retrieves the specified optional list (maps from JSON array) parameter. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        allowNull - If true allows a null value.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value as a list.
        Throws:
        JSONRPC2Error - On a bad parameter type (JSONRPC2Error.INVALID_PARAMS).
      • getStringArray

        public java.lang.String[] getStringArray​(java.lang.String name)
                                          throws JSONRPC2Error
        Retrieves the specified string array (maps from JSON array of strings) parameter.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value as a string array.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getStringArray

        public java.lang.String[] getStringArray​(java.lang.String name,
                                                 boolean allowNull)
                                          throws JSONRPC2Error
        Retrieves the specified string array (maps from JSON array of strings) parameter.
        Parameters:
        name - The parameter name.
        allowNull - If true allows a null value.
        Returns:
        The parameter value as a string array.
        Throws:
        JSONRPC2Error - On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
      • getOptStringArray

        public java.lang.String[] getOptStringArray​(java.lang.String name,
                                                    java.lang.String[] defaultValue)
                                             throws JSONRPC2Error
        Retrieves the specified optional string array (maps from JSON array of strings) parameter. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value as a string array.
        Throws:
        JSONRPC2Error - On a bad parameter type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOptStringArray

        public java.lang.String[] getOptStringArray​(java.lang.String name,
                                                    boolean allowNull,
                                                    java.lang.String[] defaultValue)
                                             throws JSONRPC2Error
        Retrieves the specified optional string array (maps from JSON array of strings) parameter. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        allowNull - If true allows a null value.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value as a string array.
        Throws:
        JSONRPC2Error - On a bad parameter type (JSONRPC2Error.INVALID_PARAMS).
      • getMap

        public java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String name)
                                                                      throws JSONRPC2Error
        Retrieves the specified map (maps from JSON object) parameter.
        Parameters:
        name - The parameter name.
        Returns:
        The parameter value as a map.
        Throws:
        JSONRPC2Error - On a missing parameter, bad type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getMap

        public java.util.Map<java.lang.String,​java.lang.Object> getMap​(java.lang.String name,
                                                                             boolean allowNull)
                                                                      throws JSONRPC2Error
        Retrieves the specified map (maps from JSON object) parameter.
        Parameters:
        name - The parameter name.
        allowNull - If true allows a null value.
        Returns:
        The parameter value as a map.
        Throws:
        JSONRPC2Error - On a missing parameter or bad type (JSONRPC2Error.INVALID_PARAMS).
      • getOptMap

        public java.util.Map<java.lang.String,​java.lang.Object> getOptMap​(java.lang.String name,
                                                                                java.util.Map<java.lang.String,​java.lang.Object> defaultValue)
                                                                         throws JSONRPC2Error
        Retrieves the specified optional map (maps from JSON object) parameter. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value as a map.
        Throws:
        JSONRPC2Error - On a bad parameter type or null value (JSONRPC2Error.INVALID_PARAMS).
      • getOptMap

        public java.util.Map<java.lang.String,​java.lang.Object> getOptMap​(java.lang.String name,
                                                                                boolean allowNull,
                                                                                java.util.Map<java.lang.String,​java.lang.Object> defaultValue)
                                                                         throws JSONRPC2Error
        Retrieves the specified optional map (maps from JSON object) parameter. If it doesn't exist the method will return the specified default value.
        Parameters:
        name - The parameter name.
        allowNull - If true allows a null value.
        defaultValue - The default return value if the parameter doesn't exist. May be null.
        Returns:
        The parameter value as a map.
        Throws:
        JSONRPC2Error - On a bad parameter type (JSONRPC2Error.INVALID_PARAMS).