Package com.ibm.json.java
Class JSONObject
java.lang.Object
java.util.AbstractMap<K,V>
 
java.util.HashMap
com.ibm.json.java.JSONObject
- All Implemented Interfaces:
- JSONArtifact,- Serializable,- Cloneable,- Map
- Direct Known Subclasses:
- OrderedJSONObject
Models a JSON Object.
 
 Extension of HashMap that only allows String keys, and values which are JSON-able. 
 
JSON-able values are: null, and instances of String, Boolean, Number, JSONObject and JSONArray.
Instances of this class are not thread-safe.
JSON-able values are: null, and instances of String, Boolean, Number, JSONObject and JSONArray.
Instances of this class are not thread-safe.
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class java.util.AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> 
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic booleanisValidObject(Object object) Return whether the object is a valid value for a property.static booleanisValidType(Class clazz) Return whether the class is a valid type of value for a property.static JSONObjectparse(InputStream is) Convert a stream of JSON text into object form.static JSONObjectConvert a stream (in reader form) of JSON text into object form.static JSONObjectConvert a String of JSON text into object form.(non-Javadoc)Convert this object into a String of JSON text.serialize(boolean verbose) Convert this object into a String of JSON text, specifying verbosity.voidConvert this object into a stream of JSON text.voidserialize(OutputStream os, boolean verbose) Convert this object into a stream of JSON text.voidConvert this object into a stream of JSON text.voidConvert this object into a stream of JSON text, specifying verbosity.toString()Over-ridden toString() method.Methods inherited from class java.util.HashMapclear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.util.AbstractMapequals, hashCode
- 
Constructor Details- 
JSONObjectpublic JSONObject()Create a new instance of this class.
 
- 
- 
Method Details- 
isValidObjectReturn whether the object is a valid value for a property.- Parameters:
- object- The object to check for validity as a JSON property value.
 
- 
isValidTypeReturn whether the class is a valid type of value for a property.- Parameters:
- clazz- The class type to check for validity as a JSON object type.
 
- 
parseConvert a stream (in reader form) of JSON text into object form.- Parameters:
- reader- The reader from which the JSON data is read.
- Returns:
- The contructed JSON Object.
- Throws:
- IOEXception- Thrown if an underlying IO error from the reader occurs, or if malformed JSON is read,
- IOException
 
- 
parseConvert a String of JSON text into object form.- Parameters:
- str- The JSON string to parse into a Java Object.
- Returns:
- The contructed JSON Object.
- Throws:
- IOEXception- Thrown if malformed JSON is read,
- IOException
 
- 
parseConvert a stream of JSON text into object form.- Parameters:
- is- The inputStream from which to read the JSON. It will assume the input stream is in UTF-8 and read it as such.
- Returns:
- The contructed JSON Object.
- Throws:
- IOEXception- Thrown if an underlying IO error from the stream occurs, or if malformed JSON is read,
- IOException
 
- 
serializeConvert this object into a stream of JSON text. Same as calling serialize(os,false); Note that encoding is always written as UTF-8, as per JSON spec.- Specified by:
- serializein interface- JSONArtifact
- Parameters:
- os- The output stream to serialize data to.
- Throws:
- IOException- Thrown on IO errors during serialization.
 
- 
serializeConvert this object into a stream of JSON text. Same as calling serialize(writer,false); Note that encoding is always written as UTF-8, as per JSON spec.- Specified by:
- serializein interface- JSONArtifact
- Parameters:
- os- The output stream to serialize data to.
- verbose- Whether or not to write the JSON text in a verbose format.
- Throws:
- IOException- Thrown on IO errors during serialization.
 
- 
serializeConvert this object into a stream of JSON text. Same as calling serialize(writer,false);- Specified by:
- serializein interface- JSONArtifact
- Parameters:
- writer- The writer which to serialize the JSON text to.
- Throws:
- IOException- Thrown on IO errors during serialization.
 
- 
serializeConvert this object into a stream of JSON text, specifying verbosity.- Specified by:
- serializein interface- JSONArtifact
- Parameters:
- writer- The writer which to serialize the JSON text to.
- Throws:
- IOException- Thrown on IO errors during serialization.
 
- 
serializeConvert this object into a String of JSON text, specifying verbosity.- Specified by:
- serializein interface- JSONArtifact
- Parameters:
- verbose- Whether or not to serialize in compressed for formatted Strings.
- Throws:
- IOException- Thrown on IO errors during serialization.
 
- 
serializeConvert this object into a String of JSON text. Same as serialize(false);- Specified by:
- serializein interface- JSONArtifact
- Throws:
- IOException- Thrown on IO errors during serialization.
 
- 
put(non-Javadoc)
- 
toStringOver-ridden toString() method. Returns the same value as serialize(), which is a compact JSON String. If an error occurs in the serialization, the return will be of format: JSON Generation Error: [] - Overrides:
- toStringin class- AbstractMap
 
 
-