Converts a {@link JsonObject} to a {@link State} object. It does not add any keys specified in the excludeKeys array
9885
public static State jsonObjectToState(JsonObject jsonObject, String... excludeKeys) {
    State state = new State();
    List<String> excludeKeysList = excludeKeys == null ? Lists.<String>newArrayList() : Arrays.asList(excludeKeys);
    for (Map.Entry<String, JsonElement> jsonObjectEntry : jsonObject.entrySet()) {
      if (!excludeKeysList.contains(jsonObjectEntry.getKey())) {
        state.setProp(jsonObjectEntry.getKey(), jsonObjectEntry.getValue().getAsString());
      }
    }
    return state;
  }
1339703
public static MutationState from(JsonObject source) {
        try {
            MutationState state = new MutationState();
            for (String bucketName : source.getNames()) {
                JsonObject bucket = source.getObject(bucketName);
                for (String vbid : bucket.getNames()) {
                    JsonArray values = bucket.getArray(vbid);
                    state.addToken(new MutationToken(
                        Long.parseLong(vbid),
                        Long.parseLong(values.getString(1)),
                        values.getLong(0),
                        bucketName
                    ));
                }
            }
            return state;
        } catch (Exception ex) {
            throw new IllegalStateException("Could not import MutationState from JSON.", ex);
        }
    }
1273850
JsonObject toJsonObject() {
        JsonObjectBuilder ob = Json.createObjectBuilder();
        ob.add("id", enrollmentID);
        ob.add("type", type);
        if (this.secret != null) {
            ob.add("secret", secret);
        }
        if (null != maxEnrollments) {

            ob.add("max_enrollments", maxEnrollments);
        }
        if (affiliation != null) {
            ob.add("affiliation", affiliation);
        }

        JsonArrayBuilder ab = Json.createArrayBuilder();
        for (Attribute attr : attrs) {
            ab.add(attr.toJsonObject());
        }
        if (caName != null) {
            ob.add(HFCAClient.FABRIC_CA_REQPROP, caName);
        }
        ob.add("attrs", ab.build());
        return ob.build();
    }
951536
private static Optional<ICondition> asNot( JsonObject json)
    {
    return
      json.containsKey( NOT_KEY)
      ? Optional.of( new Not( asCondition( json.getJsonObject( NOT_KEY))))
      : Optional.empty();
    }
855043
@Override
    public Object map(Object input) {
        String str = input.toString();
        List<Integer> oneHot = new ArrayList<>();
        int n = stateNames.size();
        Integer classIdx = statesMap.get(str);
        if (classIdx == null) {
            throw new IllegalStateException("Cannot convert categorical value to one-hot: input value (\"" + str
                    + "\") is not in the list of known categories (state names/categories: " + stateNames + ")");
        }
        for (int j = 0; j < n; j++) {
            if (j == classIdx)
                oneHot.add(1);
            else
                oneHot.add(0);
        }
        return oneHot;
    }
464524
public static <T> T toObject(JSONObject jsonObject, Class<T> clazz) {
        if (jsonObject == null) {
            return null;
        }
        return JSONObject.toJavaObject(jsonObject, clazz);
    }
150705
public JSONObject getJSONObject(String key) throws JSONException {
    Object o = get(key);
    if (o instanceof JSONObject) {
      return (JSONObject) o;
    }
    throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONObject.");
  }
1106913
private JSONObject readObject() throws JSONException {
		JSONObject result = new JSONObject();

		/* Peek to see if this is the empty object. */
		int first = nextCleanInternal();
		if (first == '}') {
			return result;
		}
		else if (first != -1) {
			this.pos--;
		}

		while (true) {
			Object name = nextValue();
			if (!(name instanceof String)) {
				if (name == null) {
					throw syntaxError("Names cannot be null");
				}
				else {
					throw syntaxError("Names must be strings, but " + name
							+ " is of type " + name.getClass().getName());
				}
			}

			/*
			 * Expect the name/value separator to be either a colon ':', an equals sign
			 * '=', or an arrow "=>". The last two are bogus but we include them because
			 * that's what the original implementation did.
			 */
			int separator = nextCleanInternal();
			if (separator != ':' && separator != '=') {
				throw syntaxError("Expected ':' after " + name);
			}
			if (this.pos < this.in.length() && this.in.charAt(this.pos) == '>') {
				this.pos++;
			}

			result.put((String) name, nextValue());

			switch (nextCleanInternal()) {
			case '}':
				return result;
			case ';':
			case ',':
				continue;
			default:
				throw syntaxError("Unterminated object");
			}
		}
	}
712546
public static Map<String, Object> jsonObjectToMap(JSONObject jsonObj)
    {
        Map<String, Object> map = new Hashtable<String, Object>();
        
        Iterator<?> iterator = jsonObj.keys();
        while (iterator.hasNext())
        {
            try {
                String key = (String)iterator.next();
                String value = jsonObj.getString(key);  // TODO what if this is a JSONObject?
                map.put(key, value);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
1302757
public JSONObject toJSONObject(JSONArray names) throws JSONException {
		if (names == null || names.size() == 0 || this.size() == 0) {
			return null;
		}
		JSONObject jo = new JSONObject();
		for (int i = 0; i < names.size(); i += 1) {
			jo.put(names.getStr(i), this.getObj(i));
		}
		return jo;
	}
450385
public JSONObject getObject(String key) {
        Object tmp = objectMap.get(key);
        return tmp == null ? null
                : tmp instanceof JSONObject ? (JSONObject) tmp : null;
    }
281595
public Object deserialize(String jsonObject) {
		if (LOGGER.isDebugEnabled()) {
			LOGGER.debug("Deserializing Json object");
		}
		XStream xstream = new XStream(new JettisonMappedXmlDriver());
		Object obj = xstream.fromXML(jsonObject);
		if (LOGGER.isDebugEnabled()) {
			LOGGER.debug("Object deserialized");
		}
		return obj;
	}
1345203
@javax.annotation.Nonnull
  public JsonObject getJson() {
    @javax.annotation.Nonnull final JsonObject json = new JsonObject();
    json.addProperty("min", min);
    json.addProperty("max", max);
    json.addProperty("negatives", negatives);
    json.addProperty("positives", positives);
    json.addProperty("zeros", zeros);
    json.addProperty("sum0", sum0);
    json.addProperty("sum1", sum1);
    json.addProperty("sum2", sum2);
    json.addProperty("sumLog", sumLog);
    return json;
  }
1268107
private static Object convert(Object x) throws JSONException {
    if (x instanceof JSONObject) {
      JSONObject jsonObject = (JSONObject) x;
      String[] names = JSONObject.getNames(jsonObject);
      if (names == null || names.length == 0) {
        return new HashMap<>(0);
      }
      HashMap<String, Object> map = new HashMap<>(names.length);
      for (String name : names) {
        Object value = jsonObject.get(name);
        map.put(name, convert(value));
      }
      return map;
    } else if (x instanceof JSONArray) {
      JSONArray jsonArray = (JSONArray) x;
      int length = jsonArray.length();
      List<Object> list = new ArrayList<>(length);
      for (int i = 0; i < length; i++) {
        list.add(convert(jsonArray.get(i)));
      }
      return list;
    } else {
      return x;
    }
  }
136066
public static JsonObject toJsonObject(Map<String, ?> map) {
        JsonObject properties = new JsonObject();
        for (Map.Entry<String, ?> property : map.entrySet()) {
            properties.add(property.getKey(), Json.value(property.getValue().toString()));
        }
        return properties;
    }
14600
@SafeVarargs
    public static @Nonnull JsonObject object(Entry<String,JsonElement>...fields) {
        JsonObject object = new JsonObject();
        object.add(fields);
        return object;
    }
627646
public static JSONObject parseObj(Object obj, boolean ignoreNullValue, boolean isOrder) {
		return new JSONObject(obj, ignoreNullValue, isOrder);
	}