public class

JsonValue

extends Object
implements Parcelable JsonSerializable
java.lang.Object
   ↳ com.urbanairship.json.JsonValue

Class Overview

A JsonValue is a representation of any value that can be described using JSON. It can contain one of the following: a JsonMap, a JsonList, a Number, a Boolean, String, or it can contain null.

JsonValues can be created from Java Objects by calling wrap(Object) or from a JSON String by callingparseString(String). The JsonValue toString() returns the JSON String representation of the object.

Summary

[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final JsonValue NULL A null representation of the JsonValue.
Public Methods
String coerceString()
Gets the contained value coerced into a String.
int describeContents()
boolean equals(Object object)
boolean getBoolean(boolean defaultValue)
Gets the contained values as a boolean.
Boolean getBoolean()
Gets the contained values as a boolean.
double getDouble(double defaultValue)
Gets the contained values as an double.
float getFloat(float defaultValue)
Gets the contained values as a float.
int getInt(int defaultValue)
Gets the contained values as an int.
Integer getInteger()
Gets the contained values as an Integer.
JsonList getList()
Gets the contained value as a JsonList.
long getLong(long defaultValue)
Gets the contained values as an long.
JsonMap getMap()
Gets the contained values as a JsonMap.
Number getNumber()
Gets the contained values as a Number.
String getString()
Gets the contained value as a String.
String getString(String defaultValue)
Gets the contained values as a String.
Object getValue()
Gets the raw value of the JsonValue.
int hashCode()
boolean isBoolean()
Checks if the value is a Boolean.
boolean isDouble()
Checks if the value is a Double.
boolean isFloat()
Checks if the value is a Float.
boolean isInteger()
Checks if the value is an Integer.
boolean isJsonList()
Checks if the value is a JsonList.
boolean isJsonMap()
Checks if the value is a JsonMap.
boolean isLong()
Checks if the value is a Long.
boolean isNull()
If the contained value is null.
boolean isNumber()
Checks if the value is a Number.
boolean isString()
Checks if the value is a String.
JsonList optList()
Gets the contained values as a JsonList.
JsonMap optMap()
Gets the contained values as a JsonMap.
String optString()
Returns the String value or an empty String.
static JsonValue parseString(String jsonString)
Parse a JSON encoded String.
JsonList requireList()
Requires the value to be a JsonList or a JsonException will be thrown.
JsonMap requireMap()
Requires the value to be a JsonMap or a JsonException will be thrown.
String requireString()
Requires the value to be a String or a JsonException will be thrown.
JsonValue toJsonValue()
Returns the objects represented as a JsonValue.
String toString()
Returns the JsonValue as a JSON encoded String.
static JsonValue wrap(Object object, JsonValue defaultValue)
Wraps any valid object into a JsonValue.
static JsonValue wrap(double value)
Wraps a double as a JsonValue.
static JsonValue wrap(boolean value)
Wraps a boolean as a JsonValue.
static JsonValue wrap(long value)
Wraps a long as a JsonValue.
static JsonValue wrap(int value)
Wraps an int as a JsonValue.
static JsonValue wrap(Object object)
Wraps any valid object into a JsonValue.
static JsonValue wrap(String value)
Wraps a String as a JsonValue.
static JsonValue wrap(char value)
Wraps a char as a JsonValue.
static JsonValue wrap(JsonSerializable value)
Wraps a JsonSerializable object as a JsonValue.
static JsonValue wrapOpt(Object object)
Wraps any valid object into a JsonValue.
void writeToParcel(Parcel dest, int flags)
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable
From interface com.urbanairship.json.JsonSerializable

Fields

public static final JsonValue NULL

A null representation of the JsonValue.

Public Methods

public String coerceString ()

Gets the contained value coerced into a String.

Returns
  • The value coerced as a String, or null if the value is not coercible into a String.

public int describeContents ()

public boolean equals (Object object)

public boolean getBoolean (boolean defaultValue)

Gets the contained values as a boolean.

Parameters
defaultValue The default value if the contained value is not a boolean.
Returns
  • The value as a boolean, or the defaultValue if the value is not a boolean.

public Boolean getBoolean ()

Gets the contained values as a boolean.

Returns
  • The value as a Boolean, or null if the value is not a Boolean.

public double getDouble (double defaultValue)

Gets the contained values as an double.

Parameters
defaultValue The default value if the contained value is not a number.
Returns
  • The value as a double, or the defaultValue if the value is not a number.

public float getFloat (float defaultValue)

Gets the contained values as a float.

Parameters
defaultValue The default value if the contained value is not a number.
Returns
  • The value as a float, or the defaultValue if the value is not a number.

public int getInt (int defaultValue)

Gets the contained values as an int.

Parameters
defaultValue The default value if the contained value is not a number.
Returns
  • The value as an int, or the defaultValue if the value is not a number.

public Integer getInteger ()

Gets the contained values as an Integer.

Returns
  • The value as an Integer, or null if the value is not set or not a number.

public JsonList getList ()

Gets the contained value as a JsonList.

Returns
  • The value as a JsonList, or null if the value is not a JsonList.

public long getLong (long defaultValue)

Gets the contained values as an long.

Parameters
defaultValue The default value if the contained value is not a number.
Returns
  • The value as a long, or the defaultValue if the value is not a number.

public JsonMap getMap ()

Gets the contained values as a JsonMap.

Returns
  • The value as JsonMap, or null if the value is not a JsonMap.

public Number getNumber ()

Gets the contained values as a Number.

Returns
  • The value as a number or null if the value is null or not a number.

public String getString ()

Gets the contained value as a String.

Returns
  • The value as a String, or null if the value is not a String.

public String getString (String defaultValue)

Gets the contained values as a String.

Parameters
defaultValue The default value if the contained value is not a String.
Returns
  • The value as a String, or the defaultValue if the value is not a String.

public Object getValue ()

Gets the raw value of the JsonValue. Will be either a String, Boolean, Long, Double, Integer, JsonMap, JsonArray, or null.

Returns
  • The raw value.

public int hashCode ()

public boolean isBoolean ()

Checks if the value is a Boolean.

Returns
  • true if the value is a Boolean, otherwise false.

public boolean isDouble ()

Checks if the value is a Double.

Returns
  • true if the value is a Double, otherwise false.

public boolean isFloat ()

Checks if the value is a Float.

Returns
  • true if the value is a Float, otherwise false.

public boolean isInteger ()

Checks if the value is an Integer.

Returns
  • true if the value is an Integer, otherwise false.

public boolean isJsonList ()

Checks if the value is a JsonList.

Returns
  • true if the value is a JsonList, otherwise false.

public boolean isJsonMap ()

Checks if the value is a JsonMap.

Returns
  • true if the value is a JsonMap, otherwise false.

public boolean isLong ()

Checks if the value is a Long.

Returns
  • true if the value is a Long, otherwise false.

public boolean isNull ()

If the contained value is null.

Returns
  • true if the contained value is null, otherwise false.

public boolean isNumber ()

Checks if the value is a Number.

Returns
  • true if the value is a Number, otherwise false.

public boolean isString ()

Checks if the value is a String.

Returns
  • true if the value is a String, otherwise false.

public JsonList optList ()

Gets the contained values as a JsonList.

Returns
  • The value as JsonList, or an empty JsonList if the value is not a JsonList.

public JsonMap optMap ()

Gets the contained values as a JsonMap.

Returns
  • The value as JsonMap, or an empty JsonMap if the value is not a JsonMap.

public String optString ()

Returns the String value or an empty String.

Returns
  • The string value or an empty String.

public static JsonValue parseString (String jsonString)

Parse a JSON encoded String.

Parameters
jsonString The json encoded String.
Returns
  • A JsonValue from the encoded String.
Throws
JsonException If the JSON was unable to be parsed.

public JsonList requireList ()

Requires the value to be a JsonList or a JsonException will be thrown.

Returns
  • The value as a list.
Throws
JsonException

public JsonMap requireMap ()

Requires the value to be a JsonMap or a JsonException will be thrown.

Returns
  • The value as a map.
Throws
JsonException

public String requireString ()

Requires the value to be a String or a JsonException will be thrown.

Returns
  • The value as a string.
Throws
JsonException

public JsonValue toJsonValue ()

Returns the objects represented as a JsonValue.

Returns
  • The object as a JsonValue.

public String toString ()

Returns the JsonValue as a JSON encoded String.

Returns
  • The value as a JSON encoded String.

public static JsonValue wrap (Object object, JsonValue defaultValue)

Wraps any valid object into a JsonValue. If the object is unable to be wrapped, the default value will be returned. See wrap(Object) for rules on object wrapping.

Parameters
object The object to wrap.
defaultValue The default value if the object is unable to be wrapped.
Returns
  • The object wrapped in a JsonValue or the default value if the object is unable to be wrapped.

public static JsonValue wrap (double value)

Wraps a double as a JsonValue.

Parameters
value The value as a double.
Returns
  • The JsonValue object.

public static JsonValue wrap (boolean value)

Wraps a boolean as a JsonValue.

Parameters
value The value as a boolean.
Returns
  • The JsonValue object.

public static JsonValue wrap (long value)

Wraps a long as a JsonValue.

Parameters
value The value as a long.
Returns
  • The JsonValue object.

public static JsonValue wrap (int value)

Wraps an int as a JsonValue.

Parameters
value The value as an int.
Returns
  • The JsonValue object.

public static JsonValue wrap (Object object)

Wraps any valid object into a JsonValue.

Objects will be wrapped with the following rules:

  • JSONObject.NULL or null will result in NULL.
  • Collections, arrays, JSONArray values will be wrapped into a JsonList
  • Maps with String keys will be wrapped into a JsonMap.
  • Strings, primitive wrapper objects, JsonMaps, and JsonLists will be wrapped directly into a JsonValue
  • Objects that implement JsonSerializable will return toJsonValue() or NULL.
  • JsonValues will be unmodified.

Parameters
object The object to wrap.
Returns
  • The object wrapped in a JsonValue.
Throws
JsonException If the object is not a supported type or contains an unsupported type.

public static JsonValue wrap (String value)

Wraps a String as a JsonValue.

Parameters
value The value as a string.
Returns
  • The JsonValue object.

public static JsonValue wrap (char value)

Wraps a char as a JsonValue.

Parameters
value The value as a char.
Returns
  • The JsonValue object.

public static JsonValue wrap (JsonSerializable value)

Wraps a JsonSerializable object as a JsonValue.

Parameters
value The value as a JsonSerializable object.
Returns
  • The JsonValue object.

public static JsonValue wrapOpt (Object object)

Wraps any valid object into a JsonValue. If the object is unable to be wrapped, NULL will be returned instead.

Parameters
object The object to wrap.
Returns
  • The object wrapped in a JsonValue or NULL.

public void writeToParcel (Parcel dest, int flags)