Package com.api.json
Class JSON
- java.lang.Object
-
- com.api.json.JSON
-
- All Implemented Interfaces:
Serializable
public class JSON extends Object implements Serializable
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JSON()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static StringcleanUpString(Object obj)Provides special formatting of embedded characters to enable valid JSON serializationstatic voidescapeSolidus(boolean set)Use to set or unset escaping solidus characters in the output.protected static StringexpandUnicode(String input)Expands the input String content to unicode sequences for non ASCII charactersprotected static ObjectgetNumber(Double dNum, String value)Parses the number corresponding with the supplied values.static booleanisValidObject(Object object)Used to determine if the supplied Object can be a valid JSON object.static booleanisValidType(Class<?> clazz)Used to determine in the supplied Class is a valid type for JSON objects.static JSONArtifactparse(InputStream is)Parses the supplied input stream to produce either aJSONObjector aJSONArray.static JSONArtifactparse(Reader reader)Parses the supplied reader to produce either aJSONObjector aJSONArraystatic JSONArtifactparse(String str)Parses a supplied String to produce aJSONObjector aJSONArray.static voidsetSpacing(int size)Provides a String of blanks for indentation (up to 60 spaces) corresponding to the supplied indentation size.
-
-
-
Method Detail
-
cleanUpString
protected static String cleanUpString(Object obj)
Provides special formatting of embedded characters to enable valid JSON serialization- Parameters:
obj- Object to be formatted- Returns:
- Formatted String representation of the supplied object with appropriate expanded character sequences.
-
escapeSolidus
public static void escapeSolidus(boolean set)
Use to set or unset escaping solidus characters in the output. By default, this is set to true for compatibility.- Parameters:
set- If true, solidus is printed as \/ rather than /
-
expandUnicode
protected static String expandUnicode(String input)
Expands the input String content to unicode sequences for non ASCII characters- Parameters:
input- String to be formatted- Returns:
- Formatted output String
-
isValidObject
public static boolean isValidObject(Object object)
Used to determine if the supplied Object can be a valid JSON object.- Parameters:
object- Object to be tested.- Returns:
- True if the supplied Object is a valid JSON object.
-
isValidType
public static boolean isValidType(Class<?> clazz)
Used to determine in the supplied Class is a valid type for JSON objects. Valid types are:String,Boolean,Integer,Double,Long,Byte,Short,Float,JSONObject, orJSONArray- Parameters:
clazz- The Class to be tested.- Returns:
- True if the supplied class is a valid type for JSON objects.
-
parse
public static JSONArtifact parse(InputStream is) throws IOException
Parses the supplied input stream to produce either aJSONObjector aJSONArray.- Parameters:
is- The input stream to be parsed.- Returns:
- The
JSONObjector theJSONArrayparsed from the input stream. - Throws:
IOException- If a parsing error occurs.
-
parse
public static JSONArtifact parse(Reader reader) throws IOException
Parses the supplied reader to produce either aJSONObjector aJSONArray- Parameters:
reader- The reader to be parsed.- Returns:
- The
JSONObjector theJSONArrayparsed from the reader. - Throws:
IOException- If a parsing error occurs.
-
parse
public static JSONArtifact parse(String str) throws IOException
Parses a supplied String to produce aJSONObjector aJSONArray.- Parameters:
str- Supplied String to be parsed.- Returns:
- The parsed
JSONObjectorJSONArray - Throws:
IOException- If a parsing error occurs.
-
setSpacing
public static void setSpacing(int size)
Provides a String of blanks for indentation (up to 60 spaces) corresponding to the supplied indentation size.- Parameters:
size- the desired indentation size.
-
-