|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.json.util.JSONUtils
public final class JSONUtils
Provides useful methods on java objects.
Method Summary | |
---|---|
static java.lang.String |
doubleToString(double d)
Produce a string from a double. |
static java.lang.String |
getFunctionParams(java.lang.String function)
Returns the params of a function literal. |
static java.lang.Class |
getInnerComponentType(java.lang.Class type)
|
static net.sf.ezmorph.MorpherRegistry |
getMorpherRegistry()
|
static java.util.Map |
getProperties(JSONObject jsonObject)
Creates a Map with all the properties of the JSONObject. |
static java.lang.Class |
getTypeClass(java.lang.Object obj)
Returns the JSON type. |
static boolean |
isArray(java.lang.Class clazz)
Tests if a Class represents an array or Collection. |
static boolean |
isArray(java.lang.Object obj)
Tests if obj is an array or Collection. |
static boolean |
isBoolean(java.lang.Class clazz)
Tests if Class represents a Boolean or primitive boolean |
static boolean |
isBoolean(java.lang.Object obj)
Tests if obj is a Boolean or primitive boolean |
static boolean |
isDouble(java.lang.Class clazz)
Tests if Class represents a primitive double or wrapper. |
static boolean |
isFunction(java.lang.Object obj)
Tests if obj is javaScript function. Obj must ba a non-null String and match |
static boolean |
isFunctionHeader(java.lang.Object obj)
Tests if obj is javaScript function header. Obj must ba a non-null String and match "^function[ ]?\\(.\*\)$" |
static boolean |
isNull(java.lang.Object obj)
Tests if the obj is a javaScript null. |
static boolean |
isNumber(java.lang.Class clazz)
Tests if Class represents a primitive number or wrapper. |
static boolean |
isNumber(java.lang.Object obj)
Tests if obj is a primitive number or wrapper. |
static boolean |
isObject(java.lang.Object obj)
Tests if obj is not a boolean, number, string or array. |
static boolean |
isString(java.lang.Class clazz)
Tests if Class represents a String or a char |
static boolean |
isString(java.lang.Object obj)
Tests if obj is a String or a char |
static boolean |
mayBeJSON(java.lang.String string)
|
static JSONDynaBean |
newDynaBean(JSONObject jsonObject)
|
static java.lang.String |
numberToString(java.lang.Number n)
Produce a string from a Number. |
static java.lang.String |
quote(java.lang.String string)
Produce a string in double quotes with backslash sequences in all the right places. |
static void |
testValidity(java.lang.Object o)
Throw an exception if the object is an NaN or infinite number. |
static java.lang.Number |
transformNumber(java.lang.Number input)
Transforms a Number into a valid javascript number. Float gets promoted to Double. Byte and Short get promoted to Integer. Long gets downgraded to Integer if possible. |
static java.lang.String |
valueToString(java.lang.Object value)
Make a JSON text of an Object value. |
static java.lang.String |
valueToString(java.lang.Object value,
int indentFactor,
int indent)
Make a prettyprinted JSON text of an object value. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.lang.String doubleToString(double d)
d
- A double.
public static java.lang.String getFunctionParams(java.lang.String function)
public static java.lang.Class getInnerComponentType(java.lang.Class type)
public static net.sf.ezmorph.MorpherRegistry getMorpherRegistry()
public static java.util.Map getProperties(JSONObject jsonObject)
public static java.lang.Class getTypeClass(java.lang.Object obj)
public static boolean isArray(java.lang.Class clazz)
public static boolean isArray(java.lang.Object obj)
public static boolean isBoolean(java.lang.Class clazz)
public static boolean isBoolean(java.lang.Object obj)
public static boolean isDouble(java.lang.Class clazz)
public static boolean isFunction(java.lang.Object obj)
public static boolean isFunctionHeader(java.lang.Object obj)
public static boolean isNull(java.lang.Object obj)
public static boolean isNumber(java.lang.Class clazz)
public static boolean isNumber(java.lang.Object obj)
public static boolean isObject(java.lang.Object obj)
public static boolean isString(java.lang.Class clazz)
public static boolean isString(java.lang.Object obj)
public static boolean mayBeJSON(java.lang.String string)
public static JSONDynaBean newDynaBean(JSONObject jsonObject) throws java.lang.Exception
java.lang.Exception
public static java.lang.String numberToString(java.lang.Number n)
n
- A Number
JSONException
- If n is a non-finite number.public static java.lang.String quote(java.lang.String string)
string
represents a
javascript function, translation of characters will not take place. This
will produce a non-conformant JSON text.
string
- A String
public static void testValidity(java.lang.Object o)
o
- The object to test.
JSONException
- If o is a non-finite number.public static java.lang.Number transformNumber(java.lang.Number input)
public static java.lang.String valueToString(java.lang.Object value)
Warning: This method assumes that the data structure is acyclical.
value
- The value to be serialized.
{
(left brace)
and ending with }
(right brace).
JSONException
- If the value is or contains an invalid number.public static java.lang.String valueToString(java.lang.Object value, int indentFactor, int indent)
Warning: This method assumes that the data structure is acyclical.
value
- The value to be serialized.indentFactor
- The number of spaces to add to each level of
indentation.indent
- The indentation of the top level.
{
(left brace)
and ending with }
(right brace).
JSONException
- If the object contains an invalid number.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |