Search in sources :

Example 76 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getLongArrValue.

public long[] getLongArrValue(String string, MultivaluedMap<String, String> queryParams) {
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    long[] res = new long[arr.size()];
    for (int i = 0; i < arr.size(); i++) {
        res[i] = arr.getJsonNumber(i).longValue();
    }
    reader.close();
    return res;
}
Also used : JsonArray(javax.json.JsonArray) JsonReader(javax.json.JsonReader)

Example 77 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getMapListStrValue.

public Map<List<String>, List<String>> getMapListStrValue(String string, MultivaluedMap<String, String> queryParams) {
    if (string.equals("")) {
        return null;
    }
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    Map<List<String>, List<String>> map = new HashMap<List<String>, List<String>>();
    for (int i = 0; i < arr.size(); i++) {
        JsonObject obj = arr.getJsonObject(i);
        if (obj.containsKey("key") && obj.containsKey("value")) {
            map.put(listStrFromJArr(obj.getJsonArray("key")), listStrFromJArr(obj.getJsonArray("value")));
        }
    }
    reader.close();
    return map;
}
Also used : JsonArray(javax.json.JsonArray) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) JsonString(javax.json.JsonString)

Example 78 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getMapStrValue.

public Map<String, String> getMapStrValue(String string, MultivaluedMap<String, String> queryParams) {
    if (string.equals("")) {
        return null;
    }
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    Map<String, String> map = new LinkedHashMap<String, String>();
    for (int i = 0; i < arr.size(); i++) {
        JsonObject obj = arr.getJsonObject(i);
        if (obj.containsKey("key") && obj.containsKey("value")) {
            map.put(obj.getString("key"), obj.getString("value"));
        }
    }
    reader.close();
    return map;
}
Also used : JsonArray(javax.json.JsonArray) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) LinkedHashMap(java.util.LinkedHashMap)

Example 79 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getListMapStringLongValue.

public Map<String, Long> getListMapStringLongValue(String string, MultivaluedMap<String, String> queryParams) {
    if (string.equals("")) {
        return null;
    }
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    Map<String, Long> map = new HashMap<String, Long>();
    for (int i = 0; i < arr.size(); i++) {
        JsonObject obj = arr.getJsonObject(i);
        Iterator<String> it = obj.keySet().iterator();
        String key = "";
        long val = -1;
        while (it.hasNext()) {
            String k = it.next();
            if (obj.get(k) instanceof JsonString) {
                key = obj.getString(k);
            } else {
                val = obj.getJsonNumber(k).longValue();
            }
        }
        if (val > 0 && !key.equals("")) {
            map.put(key, val);
        }
    }
    reader.close();
    return map;
}
Also used : JsonArray(javax.json.JsonArray) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonReader(javax.json.JsonReader) JsonObject(javax.json.JsonObject) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString)

Example 80 with JsonReader

use of javax.json.JsonReader in project scylla-jmx by scylladb.

the class APIClient method getListStrValue.

public List<String> getListStrValue(String string, MultivaluedMap<String, String> queryParams) {
    JsonReader reader = getReader(string, queryParams);
    JsonArray arr = reader.readArray();
    List<String> res = new ArrayList<String>(arr.size());
    for (int i = 0; i < arr.size(); i++) {
        res.add(arr.getString(i));
    }
    reader.close();
    return res;
}
Also used : JsonArray(javax.json.JsonArray) ArrayList(java.util.ArrayList) JsonReader(javax.json.JsonReader) JsonString(javax.json.JsonString)

Aggregations

JsonReader (javax.json.JsonReader)130 JsonObject (javax.json.JsonObject)110 StringReader (java.io.StringReader)78 Test (org.junit.Test)47 JsonArray (javax.json.JsonArray)44 JsonString (javax.json.JsonString)42 HashMap (java.util.HashMap)21 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)13 File (java.io.File)10 LinkedHashMap (java.util.LinkedHashMap)10 JsonParser (edu.harvard.iq.dataverse.util.json.JsonParser)9 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)8 InputStream (java.io.InputStream)7 Gson (com.google.gson.Gson)6 AsyncCompletionHandler (com.ning.http.client.AsyncCompletionHandler)6 Response (com.ning.http.client.Response)6 JsonParseException (edu.harvard.iq.dataverse.util.json.JsonParseException)5