Package org.mapfish.print.wrapper.json
Class PJsonObject
- java.lang.Object
-
- org.mapfish.print.wrapper.PElement
-
- org.mapfish.print.wrapper.PAbstractObject
-
- org.mapfish.print.wrapper.json.PJsonObject
-
- All Implemented Interfaces:
PObject
public class PJsonObject extends PAbstractObject
Wrapper around theJSONObject
class to have a better error management.
-
-
Constructor Summary
Constructors Constructor Description PJsonObject(org.json.JSONObject obj, java.lang.String contextName)
Constructor.PJsonObject(PElement parent, org.json.JSONObject obj, java.lang.String contextName)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
org.json.JSONObject
getInternalObj()
Get the internal json object.PJsonArray
getJSONArray(java.lang.String key)
Get a property as a json array or throw exception.PJsonObject
getJSONObject(java.lang.String key)
Get a property as a json object or throw exception.boolean
has(java.lang.String key)
Check if the object has a property with the key.int
hashCode()
boolean
isArray(java.lang.String key)
Is the property an array.java.util.Iterator<java.lang.String>
keys()
Get an iterator of all keys in this objects.java.lang.Object
opt(java.lang.String key)
Get the value for the key.PArray
optArray(java.lang.String key)
Get a property as a array or null.java.lang.Boolean
optBool(java.lang.String key)
Get a property as a boolean or null.java.lang.Double
optDouble(java.lang.String key)
Get a property as a double or null.java.lang.Float
optFloat(java.lang.String key)
Get a property as a float or null.java.lang.Integer
optInt(java.lang.String key)
Get a property as a int or null.PJsonArray
optJSONArray(java.lang.String key)
Get a property as a json array or null.PJsonArray
optJSONArray(java.lang.String key, PJsonArray defaultValue)
Get a property as a json array or default.PJsonObject
optJSONObject(java.lang.String key)
Get a property as a json object or null.java.lang.Long
optLong(java.lang.String key)
Get a property as a long or MIN_VALUE.PObject
optObject(java.lang.String key)
Get a property as a object or null.java.lang.String
optString(java.lang.String key)
Get a property as a string or null.int
size()
Get the number of properties in this object.java.lang.String
toString()
-
Methods inherited from class org.mapfish.print.wrapper.PAbstractObject
getArray, getBool, getDouble, getFloat, getInt, getLong, getObject, getString, optArray, optBool, optDouble, optFloat, optInt, optLong, optObject, optString
-
Methods inherited from class org.mapfish.print.wrapper.PElement
addPathTo, getContextName, getCurrentPath, getParent, getPath
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.mapfish.print.wrapper.PObject
getCurrentPath, getPath
-
-
-
-
Constructor Detail
-
PJsonObject
public PJsonObject(org.json.JSONObject obj, java.lang.String contextName)
Constructor.- Parameters:
obj
- the internal json elementcontextName
- the field name of this element in the parent.
-
PJsonObject
public PJsonObject(PElement parent, org.json.JSONObject obj, java.lang.String contextName)
Constructor.- Parameters:
parent
- the parent elementobj
- the internal json elementcontextName
- the field name of this element in the parent.
-
-
Method Detail
-
opt
public final java.lang.Object opt(java.lang.String key)
Description copied from interface:PObject
Get the value for the key.- Parameters:
key
- the key identifying the value to obtain.
-
optString
public final java.lang.String optString(java.lang.String key)
Get a property as a string or null.- Parameters:
key
- the property name
-
optInt
public final java.lang.Integer optInt(java.lang.String key)
Get a property as a int or null.- Parameters:
key
- the property name
-
optLong
public final java.lang.Long optLong(java.lang.String key)
Description copied from interface:PObject
Get a property as a long or MIN_VALUE.- Parameters:
key
- the property name
-
optDouble
public final java.lang.Double optDouble(java.lang.String key)
Get a property as a double or null.- Parameters:
key
- the property name
-
optFloat
public final java.lang.Float optFloat(java.lang.String key)
Get a property as a float or null.- Parameters:
key
- the property name
-
optBool
public final java.lang.Boolean optBool(java.lang.String key)
Get a property as a boolean or null.- Parameters:
key
- the property name
-
optObject
public final PObject optObject(java.lang.String key)
Get a property as a object or null.- Parameters:
key
- the property name
-
optArray
public final PArray optArray(java.lang.String key)
Get a property as a array or null.- Parameters:
key
- the property name
-
isArray
public final boolean isArray(java.lang.String key)
Description copied from interface:PObject
Is the property an array.- Parameters:
key
- the property name
-
optJSONObject
public final PJsonObject optJSONObject(java.lang.String key)
Get a property as a json object or null.- Parameters:
key
- the property name
-
getJSONObject
public final PJsonObject getJSONObject(java.lang.String key)
Get a property as a json object or throw exception.- Parameters:
key
- the property name
-
getJSONArray
public final PJsonArray getJSONArray(java.lang.String key)
Get a property as a json array or throw exception.- Parameters:
key
- the property name
-
optJSONArray
public final PJsonArray optJSONArray(java.lang.String key)
Get a property as a json array or null.- Parameters:
key
- the property name
-
optJSONArray
public final PJsonArray optJSONArray(java.lang.String key, PJsonArray defaultValue)
Get a property as a json array or default.- Parameters:
key
- the property namedefaultValue
- default
-
keys
public final java.util.Iterator<java.lang.String> keys()
Get an iterator of all keys in this objects.- Returns:
- The keys iterator
-
size
public final int size()
Get the number of properties in this object.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getInternalObj
public final org.json.JSONObject getInternalObj()
Get the internal json object.- Returns:
- The internal object
-
has
public final boolean has(java.lang.String key)
Check if the object has a property with the key.- Parameters:
key
- key to check for.
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-