Class JsonObject
- java.lang.Object
-
- com.alachisoft.ncache.runtime.JSON.JsonValueBase
-
- com.alachisoft.ncache.runtime.JSON.JsonObject
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable<java.util.Map.Entry<java.lang.String,JsonValueBase>>
public final class JsonObject extends JsonValueBase implements java.io.Serializable, java.lang.Iterable<java.util.Map.Entry<java.lang.String,JsonValueBase>>
Class represents JObject in JSON standards- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description JsonObject()
Default constructor.JsonObject(java.lang.String json, java.lang.String type)
Overloaded constructor which populates attributes by parsing given Json object string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAttribute(java.lang.String attributeName, JsonValue attributeValue)
Adds an attribute in the object.void
addAttribute(java.lang.String attributeName, JsonValueBase attributeValue)
Adds an attribute in the object.void
clear()
Removes all attributes from JSONObject.boolean
containsAttribute(java.lang.String attributeName)
Checks if the attribute exists.boolean
equals(java.lang.Object obj)
Checks if an obj is equal to this instance of Json object.java.util.Collection<java.lang.String>
getAttributeNames()
Retruns collection of all the attribute names.JsonValueBase
getAttributeValue(java.lang.String attributeName)
Gets attribute value identified by the attribute name.int
getCount()
Gets the number of attributes in the Json object.JsonValueBase
getItem(java.lang.String attributeName)
Gets the value of the specified attribute in the java object.java.util.Iterator<java.util.Map.Entry<java.lang.String,JsonValueBase>>
getIterator()
Returns theIterator
that iterates through JSONObject attributes.java.lang.String
getType()
Gets the type attribute of the Json object.java.lang.Object
getValue()
Gets the instance of the Json object.java.util.Iterator<java.util.Map.Entry<java.lang.String,JsonValueBase>>
iterator()
boolean
removeAttribute(java.lang.String attributeName)
Removes attribute from object on the basis of attribute name provided.void
setItem(java.lang.String attributeName, JsonValueBase value)
Sets the value against the specified attribute name in the Json object.void
setType(java.lang.String type)
Sets the type attribute of the Json object.java.lang.String
toString()
Returns JSONObject in string representation.-
Methods inherited from class com.alachisoft.ncache.runtime.JSON.JsonValueBase
getDataType, parse, toJson
-
-
-
-
Method Detail
-
getItem
public JsonValueBase getItem(java.lang.String attributeName)
Gets the value of the specified attribute in the java object.- Parameters:
attributeName
- The name of the attribute.- Returns:
- The value that exists against the attribute name.
-
iterator
public java.util.Iterator<java.util.Map.Entry<java.lang.String,JsonValueBase>> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.util.Map.Entry<java.lang.String,JsonValueBase>>
-
setItem
public void setItem(java.lang.String attributeName, JsonValueBase value) throws OperationFailedException
Sets the value against the specified attribute name in the Json object.- Parameters:
attributeName
- The name of the attribute.value
- The value that is to be set against the attribute name.- Throws:
OperationFailedException
-
getCount
public int getCount()
Gets the number of attributes in the Json object.- Returns:
- The number of attributes.
-
getValue
public java.lang.Object getValue()
Gets the instance of the Json object.- Overrides:
getValue
in classJsonValueBase
- Returns:
- The instance of the Json object.
-
setType
public void setType(java.lang.String type)
Sets the type attribute of the Json object.- Parameters:
type
- The type attribute of the Json object as string.
-
getType
public java.lang.String getType()
Gets the type attribute of the Json object.- Returns:
- The type attribute of the Json object.
-
getAttributeNames
public java.util.Collection<java.lang.String> getAttributeNames()
Retruns collection of all the attribute names.- Returns:
- All attribute names as a collection.
-
addAttribute
public void addAttribute(java.lang.String attributeName, JsonValue attributeValue) throws OperationFailedException
Adds an attribute in the object.- Parameters:
attributeName
- Name of the attribute.attributeValue
- JsonValue as the attribute value.- Throws:
OperationFailedException
-
addAttribute
public void addAttribute(java.lang.String attributeName, JsonValueBase attributeValue) throws OperationFailedException
Adds an attribute in the object.- Parameters:
attributeName
- Name of the attribute.attributeValue
- JsonValueBase as the attribute value.- Throws:
OperationFailedException
-
removeAttribute
public boolean removeAttribute(java.lang.String attributeName)
Removes attribute from object on the basis of attribute name provided.- Parameters:
attributeName
- The name of the attribute that is to be removed.- Returns:
- True, if exists and removed succcessfully otherwise, false.
-
getAttributeValue
public JsonValueBase getAttributeValue(java.lang.String attributeName)
Gets attribute value identified by the attribute name.- Parameters:
attributeName
- The name of the attribute.- Returns:
- The JsonValueBase corresponding to the attribute name and null if doesn't exist.
-
containsAttribute
public boolean containsAttribute(java.lang.String attributeName)
Checks if the attribute exists.- Parameters:
attributeName
- The name of attribute.- Returns:
- True, if attribute exists otherwise, false.
-
clear
public void clear()
Removes all attributes from JSONObject.
-
getIterator
public java.util.Iterator<java.util.Map.Entry<java.lang.String,JsonValueBase>> getIterator()
Returns theIterator
that iterates through JSONObject attributes.- Returns:
- The iterator instance.
-
equals
public boolean equals(java.lang.Object obj)
Checks if an obj is equal to this instance of Json object.- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- The object that is to be compared with this object.- Returns:
- True, if the specified object was equal to this object otherwise, false.
-
toString
public java.lang.String toString()
Returns JSONObject in string representation.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The string representation of the Json object.
-
-