Java Code Examples for net.minidev.json.JSONObject#entrySet()
The following examples show how to use
net.minidev.json.JSONObject#entrySet() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SecretDetector.java From snowflake-jdbc with Apache License 2.0 | 6 votes |
public static JSONObject maskJsonObject(JSONObject json) { for (Map.Entry<String, Object> entry : json.entrySet()) { if (entry.getValue() instanceof String) { entry.setValue(maskSecrets((String) entry.getValue())); } else if (entry.getValue() instanceof JSONArray) { maskJsonArray((JSONArray) entry.getValue()); } else if (entry.getValue() instanceof JSONObject) { maskJsonObject((JSONObject) entry.getValue()); } } return json; }
Example 2
Source File: TablespaceManager.java From tajo with Apache License 2.0 | 6 votes |
private void loadStorages(JSONObject json) { JSONObject spaces = (JSONObject) json.get(KEY_STORAGES); if (spaces != null) { Pair<String, Class<? extends Tablespace>> pair = null; for (Map.Entry<String, Object> entry : spaces.entrySet()) { try { pair = extractStorage(entry); } catch (ClassNotFoundException e) { LOG.warn(e); continue; } TABLE_SPACE_HANDLERS.put(pair.getFirst(), pair.getSecond()); } } }
Example 3
Source File: AttributesConverter.java From scheduler with GNU Lesser General Public License v3.0 | 6 votes |
private static void putAttributes(Attributes attrs, Element e, JSONObject entries) { for (Map.Entry<String, Object> entry : entries.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (value.getClass().equals(Boolean.class)) { attrs.put(e, key, (Boolean) value); } else if (value.getClass().equals(String.class)) { attrs.put(e, key, (String) value); } else if (value.getClass().equals(Double.class)) { attrs.put(e, key, (Double) value); } else if (value.getClass().equals(Integer.class)) { attrs.put(e, key, (Integer) value); } else { throw new ClassCastException(value.toString() + " is not a primitive (" + value.getClass() + ")"); } } }
Example 4
Source File: ReconfigurationPlanConverter.java From scheduler with GNU Lesser General Public License v3.0 | 6 votes |
private void eventsFromJSON(final JSONObject json, final Model mo, final Action action) throws JSONConverterException { final JSONObject hooks = (JSONObject) json.getOrDefault(HOOK_LABEL, new JSONObject()); for (Map.Entry<String, Object> e : hooks.entrySet()) { String k = e.getKey(); try { Hook h = Hook.valueOf(k.toUpperCase()); for (Object o : (JSONArray) e.getValue()) { action.addEvent(h, eventFromJSON(mo, o)); } } catch (IllegalArgumentException ex) { throw new JSONConverterException( "Unsupported hook type '" + k + "'", ex); } } }
Example 5
Source File: JdbcTablespace.java From tajo with Apache License 2.0 | 5 votes |
private void setJdbcProperties() { Object connPropertiesObjects = config.get(CONFIG_KEY_CONN_PROPERTIES); if (connPropertiesObjects != null) { Preconditions.checkState(connPropertiesObjects instanceof JSONObject, "Invalid jdbc_properties field in configs"); JSONObject connProperties = (JSONObject) connPropertiesObjects; for (Map.Entry<String, Object> entry : connProperties.entrySet()) { this.connProperties.put(entry.getKey(), entry.getValue()); } } }
Example 6
Source File: TablespaceManager.java From tajo with Apache License 2.0 | 5 votes |
private void loadTableSpaces(JSONObject json, boolean override) { JSONObject spaces = (JSONObject) json.get(KEY_SPACES); if (spaces != null) { for (Map.Entry<String, Object> entry : spaces.entrySet()) { JSONObject spaceDetail = (JSONObject) entry.getValue(); AddTableSpace( entry.getKey(), URI.create(spaceDetail.getAsString("uri")), Boolean.parseBoolean(spaceDetail.getAsString("default")), (JSONObject) spaceDetail.get(TABLESPACE_SPEC_CONFIGS_KEY), override); } } }
Example 7
Source File: AmbariClientCommon.java From knox with Apache License 2.0 | 5 votes |
Map<String, Map<String, AmbariCluster.ServiceConfiguration>> getActiveServiceConfigurations(String discoveryAddress, String clusterName, String discoveryUser, String discoveryPwdAlias) { Map<String, Map<String, AmbariCluster.ServiceConfiguration>> serviceConfigurations = new HashMap<>(); String serviceConfigsURL = String.format(Locale.ROOT,"%s" + AMBARI_SERVICECONFIGS_URI, discoveryAddress, clusterName); JSONObject serviceConfigsJSON = restClient.invoke(serviceConfigsURL, discoveryUser, discoveryPwdAlias); if (serviceConfigsJSON != null) { // Process the service configurations JSONArray serviceConfigs = (JSONArray) serviceConfigsJSON.get("items"); for (Object serviceConfig : serviceConfigs) { String serviceName = (String) ((JSONObject) serviceConfig).get("service_name"); JSONArray configurations = (JSONArray) ((JSONObject) serviceConfig).get("configurations"); for (Object configuration : configurations) { String configType = (String) ((JSONObject) configuration).get("type"); String configVersion = String.valueOf(((JSONObject) configuration).get("version")); Map<String, String> configProps = new HashMap<>(); JSONObject configProperties = (JSONObject) ((JSONObject) configuration).get("properties"); for (Entry<String, Object> entry : configProperties.entrySet()) { configProps.put(entry.getKey(), String.valueOf(entry.getValue())); } if (!serviceConfigurations.containsKey(serviceName)) { serviceConfigurations.put(serviceName, new HashMap<>()); } serviceConfigurations.get(serviceName).put(configType, new AmbariCluster.ServiceConfiguration(configType, configVersion, configProps)); } } } return serviceConfigurations; }
Example 8
Source File: ShareableResourceConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
private static void parseVMs(Model mo, ShareableResource rc, Object o) throws JSONConverterException { if (o != null) { try { JSONObject values = (JSONObject) o; for (Map.Entry<String, Object> e : values.entrySet()) { String k = e.getKey(); VM u = getVM(mo, Integer.parseInt(k)); int v = Integer.parseInt(e.getValue().toString()); rc.setConsumption(u, v); } } catch (ClassCastException cc) { throw new JSONConverterException("Unable to read the VMs at key 'vms'. Expect a JSONObject but got a '" + o.getClass().getName() + "'", cc); } } }
Example 9
Source File: ShareableResourceConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
private static void parseNodes(Model mo, ShareableResource rc, Object o) throws JSONConverterException { if (o != null) { try { JSONObject values = (JSONObject) o; for (Map.Entry<String, Object> e : values.entrySet()) { String k = e.getKey(); Node u = getNode(mo, Integer.parseInt(k)); int v = Integer.parseInt(e.getValue().toString()); rc.setCapacity(u, v); } } catch (ClassCastException cc) { throw new JSONConverterException("Unable to read the nodes at key '" + NODES_LABEL + "'. Expect a JSONObject but got a '" + o.getClass().getName() + "'", cc); } } }
Example 10
Source File: NamingServiceConverter.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
@Override public NamingService<? extends Element> fromJSON(Model mo, JSONObject o) throws JSONConverterException { String id = requiredString(o, ModelViewConverter.IDENTIFIER); if (!id.equals(getJSONId())) { return null; } NamingService ns; String type = requiredString(o, "type"); switch (type) { case VM.TYPE: ns = NamingService.newVMNS(); break; case Node.TYPE: ns = NamingService.newNodeNS(); break; default: throw new JSONConverterException("Unsupported type of element '" + type + "'"); } checkKeys(o, "map"); JSONObject map = (JSONObject) o.get("map"); for (Map.Entry<String, Object> e : map.entrySet()) { String n = e.getKey(); int v = Integer.parseInt(e.getValue().toString()); Element el = VM.TYPE.equals(type) ? getVM(mo, v) : getNode(mo, v); if (!ns.register(el, n)) { throw new JSONConverterException("Duplicated name '" + n + "'"); } } return ns; }
Example 11
Source File: AssetIndex.java From mclauncher-api with MIT License | 5 votes |
static AssetIndex fromJson(String name, JSONObject json) { boolean virtual = json.containsKey("virtual") && Boolean.parseBoolean(json.get("virtual").toString()); JSONObject objsObj = (JSONObject) json.get("objects"); Set<Asset> objects = new HashSet<>(); for (Entry<String, Object> objectEntry : objsObj.entrySet()) { objects.add(Asset.fromJson((JSONObject) objectEntry.getValue(), objectEntry.getKey())); } return new AssetIndex(virtual, name, objects); }
Example 12
Source File: Rule.java From mclauncher-api with MIT License | 5 votes |
static Rule fromJson(JSONObject json) { Action action; IOperatingSystem restrictedOs; String restrictedOsVersionPattern; String architecture; Map<String, Boolean> features; action = Action.valueOf(json.get("action").toString().toUpperCase()); if (json.containsKey("os")) { JSONObject os = (JSONObject) json.get("os"); if (os.containsKey("name")) restrictedOs = Platform.osByName(os.get("name").toString()); else restrictedOs = null; if (os.containsKey("arch")) architecture = os.get("arch").toString().toUpperCase(); else architecture = null; if (os.containsKey("version")) restrictedOsVersionPattern = os.get("version").toString(); else restrictedOsVersionPattern = null; } else { restrictedOs = null; restrictedOsVersionPattern = null; architecture = null; } if (json.containsKey("features")) { JSONObject featuresMap = (JSONObject) json.get("features"); Map<String, Boolean> f = new HashMap<>(); for (Map.Entry<String, Object> entry : featuresMap.entrySet()) { f.put(entry.getKey(), Boolean.valueOf(entry.getValue().toString())); } features = Collections.unmodifiableMap(f); } else { features = Collections.emptyMap(); } return new Rule(action,restrictedOs,restrictedOsVersionPattern, architecture,features); }