-
public final class JSONObjectExtensionsKt
-
-
Method Summary
Modifier and Type Method Description final static IntegersafeInt(JSONObject $self, String name)Retrieve an Int from the JSONObject safely. final static LongsafeLong(JSONObject $self, String name)Retrieve an Long from the JSONObject safely. final static DoublesafeDouble(JSONObject $self, String name)Retrieve a Double from the JSONObject safely. final static BooleansafeBool(JSONObject $self, String name)Retrieve a Boolean from the JSONObject safely. final static StringsafeString(JSONObject $self, String name)Retrieve a String from the JSONObject safely. final static JSONObjectsafeJSONObject(JSONObject $self, String name)Retrieve a JSONObject from the JSONObject safely. final static Map<String, Object>toMap(JSONObject $self)Create a Map from the JSONObject. final static List<Object>toList(JSONArray $self)Create a List from the JSONArray. final static UnitexpandJSONObject(JSONObject $self, String name, Function1<JSONObject, Unit> into)Expand into a JSONObject safely. final static <T extends Any> List<T>expandJSONArray(JSONObject $self, String name, Function1<JSONObject, T> into)final static JSONObjectputMap(JSONObject $self, Map<String, Object> map)Populate the JSONObject with the Map provided. final static JSONObjectputMap(JSONObject $self, String name, Map<String, Object> map)Populate the JSONObject as attribute name with the Map provided. final static JSONObjectputJSONObject(JSONObject $self, String name, Function1<JSONObject, Unit> expand)Put the attribute named by name with a JSONObject value, the contents of which are determined by the expand. final static <T extends Any> JSONObjectputJSONArray(JSONObject $self, String name, List<T> list, Function1<T, JSONObject> create)Put the attribute named by name with a JSONArray value, the contenxt of which are deteremined by the input. final static JSONObjectputSafe(JSONObject $self, String name, Object value)Put the name/value pair into the JSONObject. -
-
Method Detail
-
safeInt
final static Integer safeInt(JSONObject $self, String name)
Retrieve an Int from the JSONObject safely.
- Parameters:
name- The name of the attribute that contains an Int value.
-
safeLong
final static Long safeLong(JSONObject $self, String name)
Retrieve an Long from the JSONObject safely.
- Parameters:
name- The name of the attribute that contains an Int value.
-
safeDouble
final static Double safeDouble(JSONObject $self, String name)
Retrieve a Double from the JSONObject safely.
- Parameters:
name- The name of the attribute that contains a Double value.
-
safeBool
final static Boolean safeBool(JSONObject $self, String name)
Retrieve a Boolean from the JSONObject safely.
- Parameters:
name- The name of the attribute that contains a Boolean value.
-
safeString
final static String safeString(JSONObject $self, String name)
Retrieve a String from the JSONObject safely.
- Parameters:
name- The name of the attribute that contains a String value.
-
safeJSONObject
final static JSONObject safeJSONObject(JSONObject $self, String name)
Retrieve a JSONObject from the JSONObject safely.
- Parameters:
name- The name of the attribute that contains a JSONObject value.
-
toMap
final static Map<String, Object> toMap(JSONObject $self)
Create a Map from the JSONObject. Supports nested JSONObjects and JSONArrays.
-
expandJSONObject
final static Unit expandJSONObject(JSONObject $self, String name, Function1<JSONObject, Unit> into)
Expand into a JSONObject safely.
- Parameters:
name- The name of the attribute that contains a JSONObject value.into- The lambda method that will be executed to explore the JSONObject value, if the attribute exists.
-
expandJSONArray
final static <T extends Any> List<T> expandJSONArray(JSONObject $self, String name, Function1<JSONObject, T> into)
-
putMap
final static JSONObject putMap(JSONObject $self, Map<String, Object> map)
Populate the JSONObject with the Map provided.
- Parameters:
map- : The map that will contain the name/values.
-
putMap
final static JSONObject putMap(JSONObject $self, String name, Map<String, Object> map)
Populate the JSONObject as attribute name with the Map provided.
- Parameters:
name- : The name of the attribute that will contain the JSONObject value.map- : The map that will contain the name/values.
-
putJSONObject
final static JSONObject putJSONObject(JSONObject $self, String name, Function1<JSONObject, Unit> expand)
Put the attribute named by name with a JSONObject value, the contents of which are determined by the expand.
- Parameters:
name- : The name of the attribute that will contain the JSONObject value.expand- : The lambda that will be called to populate the JSONObject value.
-
putJSONArray
final static <T extends Any> JSONObject putJSONArray(JSONObject $self, String name, List<T> list, Function1<T, JSONObject> create)
Put the attribute named by name with a JSONArray value, the contenxt of which are deteremined by the input.
- Parameters:
name- : The name of the attribute that will contain the JSONArray value.list- : The list of items that will be converted into the JSONArray.create- : The lambda that will be called for each item in list, expecting a JSONObject to be added to the array.
-
putSafe
final static JSONObject putSafe(JSONObject $self, String name, Object value)
Put the name/value pair into the JSONObject. If the value provided is null, nothing will be put into the JSONObject.
- Parameters:
name- The name of the attribute the value will be saved to.value- The value to put into the JSONObject.
-
-
-
-