com.ibm.json.java

Class OrderedJSONObject

  1. java.lang.Object
  2. extended byjava.util.AbstractMap
  3. extended byjava.util.HashMap
  4. extended bycom.ibm.json.java.JSONObject
  5. extended bycom.ibm.json.java.OrderedJSONObject
All implemented interfaces:
JSONArtifact, java.io.Serializable, java.lang.Cloneable, java.util.Map

  1. public class OrderedJSONObject
  2. extends JSONObject
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.
See Also:
Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry, java.util.AbstractMap.SimpleImmutableEntry

Constructor Summary

Constructor and Description
OrderedJSONObject()
Create a new instance of this class.

Method Summary

Modifier and Type Method and Description
  1. void
clear()
(non-Javadoc)
  1. java.lang.Object
clone()
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.
  1. java.util.Iterator
getOrder()
Method to obtain the order in which the items will be serialized.
  1. static
  2. JSONObject
parse(java.io.InputStream is)
Convert a stream of JSON text into object form.
  1. static
  2. JSONObject
parse(java.io.Reader reader)
Convert a stream (in reader form) of JSON text into object form.
  1. static
  2. JSONObject
parse(java.lang.String str)
Convert a String of JSON text into object form.
  1. java.lang.Object
put(java.lang.Object key,java.lang.Object value)
Method to put a JSON'able object into the instance.
  1. java.lang.Object
remove(java.lang.Object key)
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
containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
equals, hashCode

Constructor Detail

OrderedJSONObject

  1. public OrderedJSONObject()
Create a new instance of this class.

Method Detail

parse

  1. public static JSONObject parse( java.io.Reader reader)
  2. throws java.io.IOException
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,
java.io.IOException

parse

  1. public static JSONObject parse( java.lang.String str)
  2. throws java.io.IOException
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,
java.io.IOException

parse

  1. public static JSONObject parse( java.io.InputStream is)
  2. throws java.io.IOException
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,
java.io.IOException

put

  1. public java.lang.Object put(java.lang.Object key,
  2. java.lang.Object value)
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 interface java.util.Map
Overrides:
put in class JSONObject
See Also:
HashMap.put(java.lang.Object, java.lang.Object)

remove

  1. public java.lang.Object remove( java.lang.Object key)
Method to remove an entry from the OrderedJSONObject instance.
Specified by:
remove in interface java.util.Map
Overrides:
remove in class java.util.HashMap
See Also:
HashMap.remove(java.lang.Object)

clear

  1. public void clear()
(non-Javadoc)
Specified by:
clear in interface java.util.Map
Overrides:
clear in class java.util.HashMap
See Also:
HashMap.clear()

clone

  1. public java.lang.Object clone()
Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.
Overrides:
clone in class java.util.HashMap

getOrder

  1. public java.util.Iterator 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.