
com.jelastic.api.core.utils.CommonJSONUtils Maven / Gradle / Ivy
/*Server class MD5: 2fa3816af2b5d97c0be1f650a3ad0c8e*/
package com.jelastic.api.core.utils;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* @name Jelastic API Client
* @version 8.11.2
* @copyright Jelastic, Inc.
*/
public class CommonJSONUtils {
public static Map convertJSONObjectToStringMap(JSONObject jsonObject) {
Iterator iterator = jsonObject.keys();
Map map = new HashMap<>();
while (iterator.hasNext()) {
String fieldName = iterator.next().toString();
String fieldValue = null;
if (!jsonObject.isNull(fieldName)) {
try {
fieldValue = jsonObject.getString(fieldName);
} catch (JSONException ignored) {
}
}
map.put(fieldName, fieldValue);
}
return map;
}
public static Object getFieldValueFromJson(JSONObject jsonObject, String fieldName) {
if (jsonObject == null) {
return null;
}
if (jsonObject.has(fieldName) && !jsonObject.isNull(fieldName)) {
try {
return jsonObject.get(fieldName);
} catch (JSONException e) {
return null;
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy