|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.json.util.JSONUtils
public final class JSONUtils
Provides useful methods on java objects and JSON values.
Field Summary | |
---|---|
static String |
DOUBLE_QUOTE
Constant for char " |
static String |
SINGLE_QUOTE
Constant for char ' |
Method Summary | |
---|---|
static String |
convertToJavaIdentifier(String key)
Transformes the string into a valid Java Identifier. |
static String |
doubleToString(double d)
Produce a string from a double. |
static String |
getFunctionParams(String function)
Returns the params of a function literal. |
static Class |
getInnerComponentType(Class type)
Returns the inner-most component type of an Array. |
static JavaIdentifierTransformer |
getJavaIdentifierTransformer()
Deprecated. use JsonConfig.getJavaIdentifierTransformer |
static MorpherRegistry |
getMorpherRegistry()
Returns the singleton MorpherRegistry. |
static Map |
getProperties(JSONObject jsonObject)
Creates a Map with all the properties of the JSONObject. |
static Class |
getTypeClass(Object obj)
Returns the JSON type. |
static int |
hashCode(Object value)
Returns the hashcode of value. |
static boolean |
isArray(Class clazz)
Tests if a Class represents an array or Collection. |
static boolean |
isArray(Object obj)
Tests if obj is an array or Collection. |
static boolean |
isBoolean(Class clazz)
Tests if Class represents a Boolean or primitive boolean |
static boolean |
isBoolean(Object obj)
Tests if obj is a Boolean or primitive boolean |
static boolean |
isDouble(Class clazz)
Tests if Class represents a primitive double or wrapper. |
static boolean |
isFunction(Object obj)
Tests if obj is javaScript function. |
static boolean |
isFunctionHeader(Object obj)
Tests if obj is javaScript function header. |
static boolean |
isJavaIdentifier(String str)
Returns trus if str represents a valid Java identifier. |
static boolean |
isNull(Object obj)
Tests if the obj is a javaScript null. |
static boolean |
isNumber(Class clazz)
Tests if Class represents a primitive number or wrapper. |
static boolean |
isNumber(Object obj)
Tests if obj is a primitive number or wrapper. |
static boolean |
isObject(Object obj)
Tests if obj is not a boolean, number, string or array. |
static boolean |
isString(Class clazz)
Tests if Class represents a String or a char |
static boolean |
isString(Object obj)
Tests if obj is a String or a char |
static boolean |
mayBeJSON(String string)
Tests if the String possibly represents a valid JSON String. |
static DynaBean |
newDynaBean(JSONObject jsonObject)
Creates a new MorphDynaBean from a JSONObject. |
static String |
numberToString(Number n)
Produce a string from a Number. |
static String |
quote(String string)
Produce a string in double quotes with backslash sequences in all the right places. |
static void |
setJavaIdentifierTransformer(JavaIdentifierTransformer javaIdentifierTransformer)
Deprecated. use JsonConfig.setJavaIdentifierTransformer |
static String |
stripQuotes(String input)
Strips any single-quotes or double-quotes from boths sides of the string. |
static void |
testValidity(Object o)
Throw an exception if the object is an NaN or infinite number. |
static Number |
transformNumber(Number input)
Transforms a Number into a valid javascript number. |
static String |
valueToString(Object value)
Make a JSON text of an Object value. |
static String |
valueToString(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 |
Field Detail |
---|
public static final String DOUBLE_QUOTE
public static final String SINGLE_QUOTE
Method Detail |
---|
public static String convertToJavaIdentifier(String key)
JSONException
- if the string can not be transformed.public static String doubleToString(double d)
d
- A double.
public static String getFunctionParams(String function)
public static Class getInnerComponentType(Class type)
public static JavaIdentifierTransformer getJavaIdentifierTransformer()
public static MorpherRegistry getMorpherRegistry()
public static Map getProperties(JSONObject jsonObject)
public static Class getTypeClass(Object obj)
public static int hashCode(Object value)
public static boolean isArray(Class clazz)
public static boolean isArray(Object obj)
public static boolean isBoolean(Class clazz)
public static boolean isBoolean(Object obj)
public static boolean isDouble(Class clazz)
public static boolean isFunction(Object obj)
public static boolean isFunctionHeader(Object obj)
public static boolean isJavaIdentifier(String str)
public static boolean isNull(Object obj)
public static boolean isNumber(Class clazz)
public static boolean isNumber(Object obj)
public static boolean isObject(Object obj)
public static boolean isString(Class clazz)
public static boolean isString(Object obj)
public static boolean mayBeJSON(String string)
public static DynaBean newDynaBean(JSONObject jsonObject)
public static String numberToString(Number n)
n
- A Number
JSONException
- If n is a non-finite number.public static String quote(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 setJavaIdentifierTransformer(JavaIdentifierTransformer javaIdentifierTransformer)
public static String stripQuotes(String input)
public static void testValidity(Object o)
o
- The object to test.
JSONException
- If o is a non-finite number.public static Number transformNumber(Number input)
public static String valueToString(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 String valueToString(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 |