Java Code Examples for net.minidev.json.JSONArray#isEmpty()

The following examples show how to use net.minidev.json.JSONArray#isEmpty() . 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: JSON.java    From hawkular-apm with Apache License 2.0 6 votes vote down vote up
/**
 * This method evaluates the jsonpath expression on the supplied
 * node.
 *
 * @param jsonpath The jsonpath expression
 * @param data The json data
 * @return The result, or null if not found (which may be due to an expression error)
 */
public static String evaluate(String jsonpath, Object data) {
    String json = serialize(data);

    // No jsonpath means return serialized form
    if (jsonpath == null || jsonpath.trim().isEmpty()) {
        return json;
    }

    if (json != null) {
        Object result = JsonPath.parse(json).read(jsonpath);
        if (result != null) {
            if (result.getClass() == JSONArray.class) {
                JSONArray arr=(JSONArray)result;
                if (arr.isEmpty()) {
                    result = null;
                } else if (arr.size() == 1) {
                    result = arr.get(0);
                }
            }
            return serialize(result);
        }
    }
    return null;
}
 
Example 2
Source File: PathLocator.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
public PathLocator(JSONArray pathsToFind) {
	if (pathsToFind == null || pathsToFind.isEmpty()) {
		this.pathsToFind = Collections.emptyList();
	} else {
		this.pathsToFind = new ArrayList<String>();
		for (Object s : pathsToFind) {
			this.pathsToFind.add((String) s);
		}
	}
}
 
Example 3
Source File: PathRemover.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
public PathRemover(JSONArray pathsToRemove) {
	if (pathsToRemove == null || pathsToRemove.isEmpty()) {
		this.pathsToRemove = Collections.emptyList();
	} else {
		this.pathsToRemove = new ArrayList<String>();
		for (Object s : pathsToRemove) {
			this.pathsToRemove.add((String) s);
		}
	}
}
 
Example 4
Source File: PathReplicator.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
public PathReplicator(JSONArray pathsToCopy) {
	if (pathsToCopy == null || pathsToCopy.isEmpty()) {
		this.pathsToCopy = Collections.emptyList();
	} else {
		this.pathsToCopy = new LinkedList<String>();
		for (Object s : pathsToCopy) {
			this.pathsToCopy.add((String) s);
		}
	}
}
 
Example 5
Source File: PathsRetainer.java    From json-smart-v2 with Apache License 2.0 5 votes vote down vote up
public PathsRetainer(JSONArray pathsToRetain) {
	if (pathsToRetain == null || pathsToRetain.isEmpty()) {
		this.pathsToRetain = Collections.emptyList();
	} else {
		this.pathsToRetain = new LinkedList<String>();
		for (Object s : pathsToRetain) {
			this.pathsToRetain.add((String) s);
		}
	}
}
 
Example 6
Source File: JSONPathAssertion.java    From jmeter-plugins with Apache License 2.0 5 votes vote down vote up
private boolean arrayMatched(JSONArray value) {
    if (value.isEmpty() && getExpectedValue().equals("[]")) {
        return true;
    }

    for (Object subj : value.toArray()) {
        if (isExpectNull() && subj == null) {
            return true;
        } else if (isEquals(subj)) {
            return true;
        }
    }

    return isEquals(value);
}
 
Example 7
Source File: RuleList.java    From mclauncher-api with MIT License 5 votes vote down vote up
static RuleList fromJson(JSONArray rulesArray) {
    if (rulesArray == null || rulesArray.isEmpty())
        return empty();

    List<Rule> rules = new ArrayList<>();
    for (Object r : rulesArray) {
        rules.add(Rule.fromJson((JSONObject) r));
    }

    return new RuleList(rules);
}
 
Example 8
Source File: ArrayIsEmptyAsserterImpl.java    From zerocode with Apache License 2.0 4 votes vote down vote up
@Override
public FieldAssertionMatcher actualEqualsToExpected(Object result) {
    if(result instanceof JSONArray){

        final JSONArray actualArrayValue = (JSONArray) result;

        if(actualArrayValue.isEmpty()){

            return aMatchingMessage();
        }

        return aNotMatchingMessage(path, "[]", result);

    } else {

        return aNotMatchingMessage(path, "[]", result);

    }
}