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, @Size(min = 1) 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
@Size(value = 2)
fun optCountryCode(jsonObject: JSONObject, @Size(min = 1) 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
@Size(value = 3)
fun optCurrency(jsonObject: JSONObject, @Size(min = 1) 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, @Size(min = 1) 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, @Size(min = 1) 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, @Size(min = 1) 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, @Size(min = 1) 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?, @Size(min = 1) 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.