
org.everit.json.schema.loader.OrgJsonUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.everit.json.schema Show documentation
Show all versions of org.everit.json.schema Show documentation
This is a fork of the implementation of the JSON Schema Core Draft v4 specification built with the org.json API which also supports internationalization
The newest version!
package org.everit.json.schema.loader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* Utility class simplifying working with org.json.JSONObject and JSONArray in a way that it also works
* on android.
*/
public class OrgJsonUtil {
/**
* Used as a replacement of {@code JSONObject#toMap()} (which doesn't exist in the android version of org.json).
*/
public static Map toMap(JSONObject obj) {
Map rval = new HashMap<>(obj.length());
Iterator keyIt = obj.keys();
while (keyIt.hasNext()) {
String key = keyIt.next();
Object rawValue = obj.get(key);
Object convertedValue = convertValue(rawValue);
rval.put(key, convertedValue);
}
return rval;
}
static Object convertValue(Object rawValue) {
Object convertedValue;
if (rawValue instanceof JSONObject) {
convertedValue = toMap((JSONObject) rawValue);
} else if (rawValue instanceof JSONArray) {
convertedValue = toList((JSONArray) rawValue);
} else {
convertedValue = rawValue;
}
return convertedValue;
}
/**
* Used as a replacement of {@code JSONArray#toList()} (which doesn't exist in the android version of org.json).
*/
public static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy