com.nimbusds.jose.util
Class JSONObjectUtils

java.lang.Object
  extended by com.nimbusds.jose.util.JSONObjectUtils

public class JSONObjectUtils
extends java.lang.Object

JSON object helper methods for parsing and typed retrieval of member values.

Version:
$version$ (2013-01-08)
Author:
Vladimir Dzhuvinov

Method Summary
static boolean getBoolean(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a boolean member of a JSON object.
static double getDouble(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a number member of a JSON object as double.
static float getFloat(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a number member of a JSON object float.
static int getInt(net.minidev.json.JSONObject o, java.lang.String key)
          Gets an number member of a JSON object as int.
static net.minidev.json.JSONArray getJSONArray(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a JSON array member of a JSON object.
static net.minidev.json.JSONObject getJSONObject(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a JSON object member of a JSON object.
static long getLong(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a number member of a JSON object as long.
static java.lang.String getString(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a string member of a JSON object.
static java.lang.String[] getStringArray(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a string array member of a JSON object.
static java.util.List<java.lang.String> getStringList(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a string list member of a JSON object
static java.net.URL getURL(net.minidev.json.JSONObject o, java.lang.String key)
          Gets a string member of a JSON object as java.net.URL.
static net.minidev.json.JSONObject parseJSONObject(java.lang.String s)
          Parses a JSON object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseJSONObject

public static net.minidev.json.JSONObject parseJSONObject(java.lang.String s)
                                                   throws java.text.ParseException
Parses a JSON object.

Specific JSON to Java entity mapping (as per JSON Smart):

Parameters:
s - The JSON object string to parse. Must not be null.
Returns:
The JSON object.
Throws:
java.text.ParseException - If the string cannot be parsed to a valid JSON object.

getBoolean

public static boolean getBoolean(net.minidev.json.JSONObject o,
                                 java.lang.String key)
                          throws java.text.ParseException
Gets a boolean member of a JSON object.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getInt

public static int getInt(net.minidev.json.JSONObject o,
                         java.lang.String key)
                  throws java.text.ParseException
Gets an number member of a JSON object as int.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getLong

public static long getLong(net.minidev.json.JSONObject o,
                           java.lang.String key)
                    throws java.text.ParseException
Gets a number member of a JSON object as long.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getFloat

public static float getFloat(net.minidev.json.JSONObject o,
                             java.lang.String key)
                      throws java.text.ParseException
Gets a number member of a JSON object float.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getDouble

public static double getDouble(net.minidev.json.JSONObject o,
                               java.lang.String key)
                        throws java.text.ParseException
Gets a number member of a JSON object as double.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getString

public static java.lang.String getString(net.minidev.json.JSONObject o,
                                         java.lang.String key)
                                  throws java.text.ParseException
Gets a string member of a JSON object.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getURL

public static java.net.URL getURL(net.minidev.json.JSONObject o,
                                  java.lang.String key)
                           throws java.text.ParseException
Gets a string member of a JSON object as java.net.URL.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getJSONArray

public static net.minidev.json.JSONArray getJSONArray(net.minidev.json.JSONObject o,
                                                      java.lang.String key)
                                               throws java.text.ParseException
Gets a JSON array member of a JSON object.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getStringArray

public static java.lang.String[] getStringArray(net.minidev.json.JSONObject o,
                                                java.lang.String key)
                                         throws java.text.ParseException
Gets a string array member of a JSON object.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getStringList

public static java.util.List<java.lang.String> getStringList(net.minidev.json.JSONObject o,
                                                             java.lang.String key)
                                                      throws java.text.ParseException
Gets a string list member of a JSON object

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.

getJSONObject

public static net.minidev.json.JSONObject getJSONObject(net.minidev.json.JSONObject o,
                                                        java.lang.String key)
                                                 throws java.text.ParseException
Gets a JSON object member of a JSON object.

Parameters:
o - The JSON object. Must not be null.
key - The JSON object member key. Must not be null.
Returns:
The member value.
Throws:
java.text.ParseException - If the value is missing, null or not of the expected type.


Copyright © 2013 NimbusDS. All Rights Reserved.