Class JsonInput
- java.lang.Object
-
- com.taskadapter.redmineapi.internal.json.JsonInput
-
public class JsonInput extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description JsonInput()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.json.JSONArray
getArrayNotNull(org.json.JSONObject obj, java.lang.String field)
Returns a json array as "not-null" value.static org.json.JSONArray
getArrayOrNull(org.json.JSONObject obj, java.lang.String field)
Returns a json array as "not-null" value.static java.util.Date
getDateOrNull(org.json.JSONObject obj, java.lang.String field, java.text.SimpleDateFormat dateFormat)
Fetch a date or null.static java.lang.Float
getFloatOrNull(org.json.JSONObject obj, java.lang.String field)
Fetches an optional float from an object.static int
getInt(org.json.JSONObject obj, java.lang.String field)
Fetches an int from an object.static int
getInt(org.json.JSONObject obj, java.lang.String field, int deflt)
Fetches an int from an object.static java.lang.Integer
getIntOrNull(org.json.JSONObject obj, java.lang.String field)
Fetches an optional int from an object.static <T> java.util.List<T>
getListNotNull(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser)
Parses required item list.static <T> java.util.List<T>
getListOrEmpty(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser)
Parses optional item list.static <T> java.util.List<T>
getListOrNull(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser)
Parses optional item list.static long
getLong(org.json.JSONObject obj, java.lang.String field)
Fetches a long from an object.static java.lang.Long
getLongOrNull(org.json.JSONObject obj, java.lang.String field)
Fetches an optional long from an object.static org.json.JSONObject
getObjectNotNull(org.json.JSONObject obj, java.lang.String field)
Returns a json object field for a specified object.static org.json.JSONObject
getObjectOrNull(org.json.JSONObject obj, java.lang.String field)
Returns a json object field for a specified object.static <T> T
getObjectOrNull(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser)
Retreive optional object.static boolean
getOptionalBool(org.json.JSONObject obj, java.lang.String field)
Returns an optional "boolean" field value.static java.lang.String
getStringNotNull(org.json.JSONObject obj, java.lang.String field)
Fetches a string from an object.static java.lang.String
getStringOrEmpty(org.json.JSONObject obj, java.lang.String field)
Fetches an optional string from an object.static java.lang.String
getStringOrNull(org.json.JSONObject obj, java.lang.String field)
Fetches an optional string from an object.
-
-
-
Method Detail
-
getListNotNull
public static <T> java.util.List<T> getListNotNull(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser) throws org.json.JSONException
Parses required item list.- Parameters:
obj
- object to extract a list from.field
- field to parse.parser
- single item parser.- Returns:
- parsed objects.
- Throws:
org.json.JSONException
- if format is invalid.
-
getListOrNull
public static <T> java.util.List<T> getListOrNull(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser) throws org.json.JSONException
Parses optional item list.- Parameters:
obj
- object to extract a list from.field
- field to parse.parser
- single item parser.- Returns:
- parsed objects.
- Throws:
org.json.JSONException
- if format is invalid.
-
getListOrEmpty
public static <T> java.util.List<T> getListOrEmpty(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser) throws org.json.JSONException
Parses optional item list.- Parameters:
obj
- object to extract a list from.field
- field to parse.parser
- single item parser.- Returns:
- parsed objects.
- Throws:
org.json.JSONException
- if format is invalid.
-
getDateOrNull
public static java.util.Date getDateOrNull(org.json.JSONObject obj, java.lang.String field, java.text.SimpleDateFormat dateFormat) throws org.json.JSONException
Fetch a date or null.- Parameters:
obj
- object to get.field
- field to use.dateFormat
- field date format.- Returns:
- data format.
- Throws:
org.json.JSONException
- if error occurs.
-
getStringOrNull
public static java.lang.String getStringOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Fetches an optional string from an object.- Parameters:
obj
- object to get a field from.field
- field to get a value from.- Throws:
org.json.JSONException
- if value is not valid
-
getOptionalBool
public static boolean getOptionalBool(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Returns an optional "boolean" field value. If field is absent or set tonull
, this method returnsfalse
.- Parameters:
obj
- object to get a field from.field
- field to get a value for.- Returns:
- boolean value.
- Throws:
org.json.JSONException
- if input is not valid (field value is not boolean).
-
getStringOrEmpty
public static java.lang.String getStringOrEmpty(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Fetches an optional string from an object. Absent value is returned as an empty string instead of null.- Parameters:
obj
- object to get a field from.field
- field to get a value from.- Throws:
org.json.JSONException
- if value is not valid
-
getStringNotNull
public static java.lang.String getStringNotNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Fetches a string from an object.- Parameters:
obj
- object to get a field from.field
- field to get a value from.- Throws:
org.json.JSONException
- if value is not valid, not exists, etc...
-
getInt
public static int getInt(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Fetches an int from an object.- Parameters:
obj
- object to get a field from.field
- field to get a value from.- Throws:
org.json.JSONException
- if value is not valid, not exists, etc...
-
getInt
public static int getInt(org.json.JSONObject obj, java.lang.String field, int deflt) throws org.json.JSONException
Fetches an int from an object.- Parameters:
obj
- object to get a field from.field
- field to get a value from.deflt
- default value.- Throws:
org.json.JSONException
- if value is not valid, not exists, etc...
-
getIntOrNull
public static java.lang.Integer getIntOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Fetches an optional int from an object.- Parameters:
obj
- object to get a field from.field
- field to get a value from.- Throws:
org.json.JSONException
- if value is not valid, not exists, etc...
-
getLong
public static long getLong(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Fetches a long from an object.- Parameters:
obj
- object to get a field from.field
- field to get a value from.- Throws:
org.json.JSONException
- if value is not valid, not exists, etc...
-
getLongOrNull
public static java.lang.Long getLongOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Fetches an optional long from an object.- Parameters:
obj
- object to get a field from.field
- field to get a value from.- Throws:
org.json.JSONException
- if value is not valid, not exists, etc...
-
getFloatOrNull
public static java.lang.Float getFloatOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Fetches an optional float from an object.- Parameters:
obj
- object to get a field from.field
- field to get a value from.- Throws:
org.json.JSONException
- if value is not valid, not exists, etc...
-
getObjectOrNull
public static <T> T getObjectOrNull(org.json.JSONObject obj, java.lang.String field, JsonObjectParser<T> parser) throws org.json.JSONException
Retreive optional object.- Parameters:
obj
- object to parse.field
- field part.parser
- parset ojbect.- Returns:
- parsed object.
- Throws:
org.json.JSONException
- if value is not valid.
-
getArrayOrNull
public static org.json.JSONArray getArrayOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Returns a json array as "not-null" value.- Parameters:
obj
- object to get a value from.field
- field to get a value from.- Returns:
- json array.
- Throws:
org.json.JSONException
-
getArrayNotNull
public static org.json.JSONArray getArrayNotNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Returns a json array as "not-null" value.- Parameters:
obj
- object to get a value from.field
- field to get a value from.- Returns:
- json array.
- Throws:
org.json.JSONException
-
getObjectNotNull
public static org.json.JSONObject getObjectNotNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Returns a json object field for a specified object.- Parameters:
obj
- object to get a field from.field
- returned field.- Returns:
- object field.
- Throws:
org.json.JSONException
- if target field is not an object.
-
getObjectOrNull
public static org.json.JSONObject getObjectOrNull(org.json.JSONObject obj, java.lang.String field) throws org.json.JSONException
Returns a json object field for a specified object.- Parameters:
obj
- object to get a field from.field
- returned field.- Returns:
- object field.
- Throws:
org.json.JSONException
- if target field is not an object.
-
-