Java Code Examples for com.eclipsesource.json.JsonValue#isArray()

The following examples show how to use com.eclipsesource.json.JsonValue#isArray() . 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: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 6 votes vote down vote up
private void decomposeJSONValue(String name, JsonValue val, Map<String, String> map)
{
	if (val.isObject())
	{
		JsonObject obj = val.asObject();
		for (String memberName : obj.names())
		{
			this.decomposeJSONValue(name + "." + memberName, obj.get(memberName), map);
		}
	} else if (val.isArray())
	{
		JsonArray arr = val.asArray();
		for (int i = 0; i < arr.size(); i++)
		{
			this.decomposeJSONValue(name + "[" + i + "]", arr.get(i), map);
		}
	} else
	{
		map.put(name, val.toString());
	}
}
 
Example 2
Source File: ZCashClientCaller.java    From zencash-swing-wallet-ui with MIT License 5 votes vote down vote up
private JsonArray executeCommandAndGetJsonArray(String command1, String command2, String command3)
	throws WalletCallException, IOException, InterruptedException
{
	JsonValue response = this.executeCommandAndGetJsonValue(command1, command2, command3);

	if (response.isArray())
	{
		return response.asArray();
	} else
	{
		throw new WalletCallException("Unexpected non-array response from wallet: " + response.toString());
	}
}
 
Example 3
Source File: JsonConfig.java    From ServerSync with GNU General Public License v3.0 5 votes vote down vote up
private static JsonArray getArray(JsonObject root, String name) throws IOException {
    JsonValue jsv = root.get(name);
    if (jsv.isNull()) {
        throw new IOException(String.format("No %s value present in configuration file", name));
    }
    if (!jsv.isArray()) {
        throw new IOException(String.format("Invalid value for %s, expected array", name));
    }
    return jsv.asArray();
}
 
Example 4
Source File: BlockJson.java    From Cubes with MIT License 5 votes vote down vote up
@Override
public ItemStackPlaceholder[] parse(JsonValue prop) {
  if (prop.isArray()) {
    JsonArray jsonArray = prop.asArray();
    ItemStackPlaceholder[] itemStacks = new ItemStackPlaceholder[jsonArray.size()];
    for (int i = 0; i < itemStacks.length; i++) {
      itemStacks[i] = parseSingle(jsonArray.get(i).asObject());
    }
    return itemStacks;
  } else {
    return new ItemStackPlaceholder[]{parseSingle(prop.asObject())};
  }
}
 
Example 5
Source File: JsonRunner_Test.java    From minimal-json with MIT License 5 votes vote down vote up
private boolean equalsIgnoreOrder(JsonValue value1, JsonValue value2) {
  if (value1.isObject()) {
    return equalsIgnoreOrder(value1.asObject(), value2);
  } else if (value1.isArray()) {
    return equalsIgnoreOrder(value1.asArray(), value2);
  }
  return value1.equals(value2);
}
 
Example 6
Source File: JsonRunner_Test.java    From minimal-json with MIT License 5 votes vote down vote up
private boolean equalsIgnoreOrder(JsonArray array1, JsonValue value2) {
  if (!value2.isArray()) {
    return false;
  }
  JsonArray array2 = value2.asArray();
  if (array1.size() != array2.size()) {
    return false;
  }
  for (int i = 0; i < array1.size(); i++) {
    if (!equalsIgnoreOrder(array2.get(i), array2.get(i))) {
      return false;
    }
  }
  return true;
}
 
Example 7
Source File: AndroidInjections.java    From CrossMobile with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void fromArray(JsonValue data, Collection<String> target) {
    if (data != null && data.isArray())
        for (JsonValue item : data.asArray())
            target.add(item.asString());
}
 
Example 8
Source File: ArrayJsonRule.java    From dungeon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void validate(JsonValue value) {
  if (!value.isArray()) {
    throw new IllegalArgumentException(value + " is not an array.");
  }
}