Package org.ghotibeaun.json
Interface JSONObject
- All Superinterfaces:
Comparable<JSONNode>
,JSONMapNode
,JSONNode
,Serializable
public interface JSONObject extends JSONMapNode
A JSON Object consisting of a collection of key-value pairs
- Author:
- Jim Earley (xml.jim@gmail.com)
-
Method Summary
Modifier and Type Method Description boolean
getBoolean(String key)
Return a booleanint
getInt(String key)
Return an integerJSONArray
getJSONArray(String key)
Return a JSONArrayJSONObject
getJSONObject(String key)
Return a JSONObject with the associated keylong
getLong(String key)
Return a long valueNumber
getNumber(String key)
Return a Number.String
getString(String key)
Return a Stringdefault <T> T
getValue(String key)
Return a casted valueJSONValueType
getValueType(String key)
Returns the JSON value typedefault void
merge(JSONObject secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)
Merge another JSONObject into this instance.default JSONObject
mergeToCopy(JSONObject secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)
Merge the current JSONObject instance with another and return the merged instance.void
put(String key, boolean b)
Adds or replaces a boolean valuevoid
put(String key, Number n)
Adds or replaces a number valuevoid
put(String key, String s)
Adds or replaces a String valuevoid
put(String key, JSONArray a)
Adds or replaces a JSONArray valuedefault void
put(String key, JSONNode node)
Set a JSONNode (either a JSONObject or JSONArray)void
put(String key, JSONObject o)
Adds or replaces a JSONObject valuevoid
putNull(String key)
Put a null value associated with a keyMethods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface org.ghotibeaun.json.JSONMapNode
clear, containsKey, elements, get, getMap, isNull, keys, keySet, names, put, put, put, putAll, putAllRaw, remove, size, valueList, values
Methods inherited from interface org.ghotibeaun.json.JSONNode
asJSONArray, asJSONObject, isArray, isEquivalent, isObject, prettyPrint, prettyPrint, select, select, select, selectValue, selectValue, selectValue, toJSONString, write, write, write, write, write, write, write, write
-
Method Details
-
put
Adds or replaces a number value- Parameters:
key
- the keyn
- the number
-
put
Adds or replaces a String value- Parameters:
key
- the keys
- the string value
-
put
Adds or replaces a boolean value- Parameters:
key
- the keyb
- the boolean value
-
put
Set a JSONNode (either a JSONObject or JSONArray)- Parameters:
key
- the keynode
- the JSONNode
-
put
Adds or replaces a JSONArray value- Parameters:
key
- the keya
- the JSONArray
-
put
Adds or replaces a JSONObject value- Parameters:
key
- the keyo
- the JSONObject
-
putNull
Put a null value associated with a key- Parameters:
key
- the key
-
getJSONObject
Return a JSONObject with the associated key- Parameters:
key
- the key- Returns:
- a JSONObject
-
getJSONArray
Return a JSONArray- Parameters:
key
- the key- Returns:
- a JSONArray
-
getNumber
Return a Number. Value can be cast to the appropriate underlying type- Parameters:
key
- the key- Returns:
- a Number
-
getLong
Return a long value- Parameters:
key
- the key- Returns:
- long value
-
getInt
Return an integer- Parameters:
key
- the key- Returns:
- the integer value
-
getBoolean
Return a boolean- Parameters:
key
- the key- Returns:
- the boolean value
-
getValueType
Returns the JSON value type- Parameters:
key
- the key- Returns:
- the value type
-
getString
Return a String- Parameters:
key
- the key- Returns:
- the String value
-
getValue
Return a casted value- Type Parameters:
T
- The cast type- Parameters:
key
- the key- Returns:
- the casted value
-
merge
default void merge(JSONObject secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)Merge another JSONObject into this instance.HERE THERE BE DRAGONS: Once the merge happens, the original Node value is replaced. Know your data
- Parameters:
secondary
- the other JSONObject instance to mergearrayConflict
- the Array Conflict Strategy to useobjectConflict
- the Object Conflict Strategy to use
-
mergeToCopy
default JSONObject mergeToCopy(JSONObject secondary, ArrayConflict arrayConflict, ObjectConflict objectConflict)Merge the current JSONObject instance with another and return the merged instance. The original instance is left in its original state.- Parameters:
secondary
- the other JSONObject instance to mergearrayConflict
- the Array Conflict Strategy to useobjectConflict
- the Object Conflict Strategy to use- Returns:
-