StripeJsonUtils

A set of JSON parsing utility functions.

Functions

Link copied to clipboard
fun jsonArrayToList(jsonArray: JSONArray?): List<Any>?

Converts a JSONArray to a List.

Link copied to clipboard
fun jsonObjectToMap(jsonObject: JSONObject?): Map<String, Any?>?

Convert a JSONObject to a Map.

Link copied to clipboard

Convert a JSONObject to a flat, string-keyed and string-valued map. All values are recorded as strings.

Link copied to clipboard
fun mapToJsonObject(mapObject: Map<String, *>?): JSONObject?

Converts a string-keyed Map into a JSONObject. This will cause a ClassCastException if any sub-map has keys that are not Strings.

Link copied to clipboard
fun nullIfNullOrEmpty(possibleNull: String?): String?
Link copied to clipboard
fun optBoolean(jsonObject: JSONObject, fieldName: String): Boolean

Calls through to JSONObject.optBoolean only in the case that the key exists. This returns null if the key is not in the object.

Link copied to clipboard
fun optCountryCode(jsonObject: JSONObject, fieldName: String): String?

Calls through to JSONObject.optString while safely converting the raw string "null" and the empty string to null, along with any value that isn't a two-character string.

Link copied to clipboard
fun optCurrency(jsonObject: JSONObject, fieldName: String): String?

Calls through to JSONObject.optString while safely converting the raw string "null" and the empty string to null, along with any value that isn't a three-character string.

Link copied to clipboard
fun optHash(jsonObject: JSONObject, fieldName: String): Map<String, String>?

Calls through to JSONObject.optJSONObject and then uses jsonObjectToStringMap on the result.

Link copied to clipboard
fun optInteger(jsonObject: JSONObject, fieldName: String): Int?

Calls through to JSONObject.optInt only in the case that the key exists. This returns null if the key is not in the object.

Link copied to clipboard
fun optLong(jsonObject: JSONObject, fieldName: String): Long?

Calls through to JSONObject.optLong only in the case that the key exists. This returns null if the key is not in the object.

Link copied to clipboard
fun optMap(jsonObject: JSONObject, fieldName: String): Map<String, Any?>?

Calls through to JSONObject.optJSONObject and then uses jsonObjectToMap on the result.

Link copied to clipboard
fun optString(jsonObject: JSONObject?, fieldName: String): String?

Calls through to JSONObject.optString while safely converting the raw string "null" and the empty string to null. Will not throw an exception if the field isn't found.