Package com.ibm.json.java
Class OrderedJSONObject
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap
com.ibm.json.java.JSONObject
com.ibm.json.java.OrderedJSONObject
- All Implemented Interfaces:
JSONArtifact
,Serializable
,Cloneable
,Map
Extension of the basic JSONObject. This class allows control of the serialization order of attributes.
The order in which items are put into the instance controls the order in which they are serialized out. For example, the
last item put is the last item serialized.
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 Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
(non-Javadoc)clone()
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.getOrder()
Method to obtain the order in which the items will be serialized.static JSONObject
parse
(InputStream is) Convert a stream of JSON text into object form.static JSONObject
Convert a stream (in reader form) of JSON text into object form.static JSONObject
Convert a String of JSON text into object form.Method to put a JSON'able object into the instance.Method to remove an entry from the OrderedJSONObject instance.Methods inherited from class com.ibm.json.java.JSONObject
isValidObject, isValidType, serialize, serialize, serialize, serialize, serialize, serialize, toString
Methods inherited from class java.util.HashMap
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode
-
Constructor Details
-
OrderedJSONObject
public OrderedJSONObject()Create a new instance of this class.
-
-
Method Details
-
parse
Convert 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. Note that the JSONObject will be an instance of OrderedJSONObject and as such, attribute order is maintained.
- Throws:
IOEXception
- Thrown if an underlying IO error from the reader occurs, or if malformed JSON is read,IOException
-
parse
Convert a String of JSON text into object form.- Parameters:
str
- The JSON string to parse into a Java Object.- Returns:
- The contructed JSON Object. Note that the JSONObject will be an instance of OrderedJSONObject and as such, attribute order is maintained.
- Throws:
IOEXception
- Thrown if malformed JSON is read,IOException
-
parse
Convert 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. Note that the JSONObject will be an instance of OrderedJSONObject and as such, attribute order is maintained.
- Throws:
IOEXception
- Thrown if an underlying IO error from the stream occurs, or if malformed JSON is read,IOException
-
put
Method to put a JSON'able object into the instance. Note that the order of initial puts controls the order of serialization. Meaning that the first time an item is put into the object determines is position of serialization. Subsequent puts with the same key replace the existing entry value and leave serialization position alone. For moving the position, the object must be removed, then re-put.- Specified by:
put
in interfaceMap
- Overrides:
put
in classJSONObject
- See Also:
-
remove
Method to remove an entry from the OrderedJSONObject instance. -
clear
public void clear()(non-Javadoc) -
clone
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned. -
getOrder
Method to obtain the order in which the items will be serialized.- Returns:
- An iterator that represents the attribute names in the order that they will be serialized.
-