Example usage for com.google.gson JsonArray JsonArray

List of usage examples for com.google.gson JsonArray JsonArray

Introduction

In this page you can find the example usage for com.google.gson JsonArray JsonArray.

Prototype

public JsonArray() 

Source Link

Document

Creates an empty JsonArray.

Usage

From source file:com.balajeetm.mystique.util.gson.lever.JsonQuery.java

License:Open Source License

/**
 * Equals filter./*from ww  w.  ja  v  a 2  s  . c om*/
 *
 * @param json the json
 * @param condition the condition
 * @return the boolean
 */
private Boolean equalsFilter(JsonElement json, JsonObject condition) {
    return jsonLever.asJsonElement(condition.get("value"), JsonNull.INSTANCE)
            .equals(jsonLever.get(json, jsonLever.asJsonArray(condition.get("field"), new JsonArray())));
}

From source file:com.balajeetm.mystique.util.gson.lever.JsonQuery.java

License:Open Source License

/**
 * In filter.//from w  w  w  .  j av  a  2 s  .  c  om
 *
 * @param json the json
 * @param condition the condition
 * @return the boolean
 */
private Boolean inFilter(JsonElement json, JsonObject condition) {
    return jsonLever.asJsonArray(condition.get("value"), new JsonArray())
            .contains(jsonLever.get(json, jsonLever.asJsonArray(condition.get("field"), new JsonArray())));
}

From source file:com.baomidou.springwind.util.yuntongxin.CCPRestSDK.java

License:Open Source License

private HashMap<String, Object> jsonToMap(String result) {
    HashMap<String, Object> hashMap = new HashMap<String, Object>();
    JsonParser parser = new JsonParser();
    JsonObject asJsonObject = parser.parse(result).getAsJsonObject();
    Set<Entry<String, JsonElement>> entrySet = asJsonObject.entrySet();
    HashMap<String, Object> hashMap2 = new HashMap<String, Object>();

    for (Entry<String, JsonElement> m : entrySet) {
        if ("statusCode".equals(m.getKey()) || "statusMsg".equals(m.getKey()))
            hashMap.put(m.getKey(), m.getValue().getAsString());
        else {//  www.j  ava2s.c  om
            if ("SubAccount".equals(m.getKey()) || "totalCount".equals(m.getKey())
                    || "smsTemplateList".equals(m.getKey()) || "token".equals(m.getKey())
                    || "callSid".equals(m.getKey()) || "state".equals(m.getKey())
                    || "downUrl".equals(m.getKey())) {
                if (!"SubAccount".equals(m.getKey()) && !"smsTemplateList".equals(m.getKey()))
                    hashMap2.put(m.getKey(), m.getValue().getAsString());
                else {
                    try {
                        if ((m.getValue().toString().trim().length() <= 2)
                                && !m.getValue().toString().contains("[")) {
                            hashMap2.put(m.getKey(), m.getValue().getAsString());
                            hashMap.put("data", hashMap2);
                            break;
                        }
                        if (m.getValue().toString().contains("[]")) {
                            hashMap2.put(m.getKey(), new JsonArray());
                            hashMap.put("data", hashMap2);
                            continue;
                        }
                        JsonArray asJsonArray = parser.parse(m.getValue().toString()).getAsJsonArray();
                        ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>();
                        for (JsonElement j : asJsonArray) {
                            Set<Entry<String, JsonElement>> entrySet2 = j.getAsJsonObject().entrySet();
                            HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                            for (Entry<String, JsonElement> m2 : entrySet2) {
                                hashMap3.put(m2.getKey(), m2.getValue().getAsString());
                            }
                            arrayList.add(hashMap3);
                        }
                        hashMap2.put(m.getKey(), arrayList);
                    } catch (Exception e) {
                        JsonObject asJsonObject2 = parser.parse(m.getValue().toString()).getAsJsonObject();
                        Set<Entry<String, JsonElement>> entrySet2 = asJsonObject2.entrySet();
                        HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                        for (Entry<String, JsonElement> m2 : entrySet2) {
                            hashMap3.put(m2.getKey(), m2.getValue().getAsString());
                        }
                        hashMap2.put(m.getKey(), hashMap3);
                        hashMap.put("data", hashMap2);
                    }

                }
                hashMap.put("data", hashMap2);
            } else {

                JsonObject asJsonObject2 = parser.parse(m.getValue().toString()).getAsJsonObject();
                Set<Entry<String, JsonElement>> entrySet2 = asJsonObject2.entrySet();
                HashMap<String, Object> hashMap3 = new HashMap<String, Object>();
                for (Entry<String, JsonElement> m2 : entrySet2) {
                    hashMap3.put(m2.getKey(), m2.getValue().getAsString());
                }
                if (hashMap3.size() != 0) {
                    hashMap2.put(m.getKey(), hashMap3);
                } else {
                    hashMap2.put(m.getKey(), m.getValue().getAsString());
                }
                hashMap.put("data", hashMap2);
            }
        }
    }
    return hashMap;
}

From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java

License:Open Source License

public JsonObject listUsers(UserListMode listMode) throws RiakCSException {
    if (endpointIsS3())
        throw new RiakCSException("Not Supported on AWS S3");

    JsonObject result = null;// w  w  w  . j ava  2s .  c  om

    try {
        Map<String, String> headers = new HashMap<String, String>();
        headers.put("Accept", "application/json");

        String filterArgument = "";
        if (listMode == UserListMode.ENABLED_ONLY)
            filterArgument = "?status=enabled";
        else if (listMode == UserListMode.DISABLED_ONLY)
            filterArgument = "?status=disabled";

        CommunicationLayer comLayer = getCommunicationLayer();

        URL url = comLayer.generateCSUrl("/riak-cs/users" + filterArgument);
        HttpURLConnection connection = comLayer.makeCall(CommunicationLayer.HttpMethod.GET, url, null, headers);
        InputStreamReader inputStreamReader = new InputStreamReader(connection.getInputStream(), "UTF-8");

        JsonArray userList = new JsonArray();

        BufferedReader reader = new BufferedReader(inputStreamReader);
        for (String line; (line = reader.readLine()) != null;) {
            if (line.startsWith("[")) {
                JsonArray aUserlist = new JsonParser().parse(line).getAsJsonArray();
                userList.addAll(aUserlist);
            }
        }

        result = new JsonObject();
        result.add("userlist", userList);

    } catch (Exception e) {
        throw new RiakCSException(e);
    }

    return result;
}

From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java

License:Open Source License

public JsonObject listBuckets() throws RiakCSException {
    CommunicationLayer comLayer = getCommunicationLayer();

    JsonObject bucketList = null;// w ww.j  a  v a 2s .c  o  m

    try {
        URL url = comLayer.generateCSUrl("", "", EMPTY_STRING_MAP);
        HttpURLConnection conn = comLayer.makeCall(CommunicationLayer.HttpMethod.GET, url);
        Document xmlDoc = XMLUtils.parseToDocument(conn.getInputStream(), debugModeEnabled);

        bucketList = new JsonObject();
        JsonArray buckets = new JsonArray();
        for (Node node : XMLUtils.xpathToNodeList("//Buckets/Bucket", xmlDoc)) {
            JsonObject bucket = new JsonObject();
            bucket.addProperty("name", XMLUtils.xpathToContent("Name", node));
            bucket.addProperty("creationDate", XMLUtils.xpathToContent("CreationDate", node));
            buckets.add(bucket);
        }

        bucketList.add("bucketList", buckets);
        JsonObject owner = new JsonObject();
        owner.addProperty("id", XMLUtils.xpathToContent("//Owner/ID", xmlDoc));
        owner.addProperty("displayName", XMLUtils.xpathToContent("//Owner/DisplayName", xmlDoc));

        bucketList.add("owner", owner);

    } catch (Exception e) {
        throw new RiakCSException(e);
    }

    return bucketList;
}

From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java

License:Open Source License

public JsonObject listObjects(String bucketName, boolean extendedList) throws RiakCSException {
    //TODO switch to more streaming type of mode
    JsonObject result = new JsonObject();

    try {//ww  w . j a  va2 s. c  om
        result.addProperty("bucketName", bucketName);

        boolean isTruncated = true;
        while (isTruncated) {
            CommunicationLayer comLayer = getCommunicationLayer();

            URL url = comLayer.generateCSUrl(bucketName, "", EMPTY_STRING_MAP);
            HttpURLConnection conn = comLayer.makeCall(CommunicationLayer.HttpMethod.GET, url);

            JsonArray objectList = new JsonArray();

            Document xmlDoc = XMLUtils.parseToDocument(conn.getInputStream(), debugModeEnabled);
            List<Node> nodeList = XMLUtils.xpathToNodeList("//Contents", xmlDoc);
            for (Node node : nodeList) {
                JsonObject object = new JsonObject();
                object.addProperty("key", XMLUtils.xpathToContent("Key", node));
                if (extendedList) {
                    object.addProperty("size", XMLUtils.xpathToContent("Size", node));
                    object.addProperty("lastModified", XMLUtils.xpathToContent("LastModified", node));
                    object.addProperty("etag", XMLUtils.xpathToContent("ETag", node));

                    JsonObject owner = new JsonObject();
                    owner.addProperty("id", XMLUtils.xpathToContent("Owner/ID", node));
                    owner.addProperty("displayName", XMLUtils.xpathToContent("Owner/DisplayName", node));
                    object.add("owner", owner);
                }

                objectList.add(object);
            }

            result.add("objectList", objectList);
            isTruncated = "true".equals(XMLUtils.xpathToContent("//IsTruncated", xmlDoc));
        }

    } catch (Exception e) {
        throw new RiakCSException(e);
    }

    return result;
}

From source file:com.basho.riakcs.client.impl.RiakCSClientImpl.java

License:Open Source License

private JsonObject getAclImpl(String bucketName, String objectKey) throws Exception {
    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("acl", null);

    CommunicationLayer comLayer = getCommunicationLayer();

    URL url = comLayer.generateCSUrl(bucketName, objectKey, parameters);
    HttpURLConnection conn = comLayer.makeCall(CommunicationLayer.HttpMethod.GET, url);

    Document xmlDoc = XMLUtils.parseToDocument(conn.getInputStream(), debugModeEnabled);
    JsonObject acl = new JsonObject();
    JsonArray grantsList = new JsonArray();

    for (Node grantNode : XMLUtils.xpathToNodeList("//Grant", xmlDoc)) {
        JsonObject grant = new JsonObject();
        grant.addProperty("permission", XMLUtils.xpathToContent("Permission", grantNode));

        String type = XMLUtils.xpathToContent("Grantee/@type", grantNode);

        JsonObject grantee = new JsonObject();
        grantee.addProperty("type", type);

        if (type.equals("Group")) {
            grantee.addProperty("uri", XMLUtils.xpathToContent("Grantee/URI", grantNode));
        } else {//w  w w  .  j  av  a  2s.  co  m
            grantee.addProperty("id", XMLUtils.xpathToContent("Grantee/ID", grantNode));
            grantee.addProperty("displayName", XMLUtils.xpathToContent("Grantee/DisplayName", grantNode));
        }
        grant.add("grantee", grantee);
        grantsList.add(grant);
    }
    acl.add("grantsList", grantsList);
    JsonObject owner = new JsonObject();
    owner.addProperty("id", XMLUtils.xpathToContent("//Owner/ID", xmlDoc));
    owner.addProperty("displayName", XMLUtils.xpathToContent("//Owner/DisplayName", xmlDoc));
    acl.add("owner", owner);
    return acl;
}

From source file:com.bekwam.resignator.model.ConfigurationJSONAdapter.java

License:Apache License

private JsonArray serializeRecentProfiles(List<String> recentProfiles) {
    JsonArray rps = new JsonArray();
    for (String rp : recentProfiles) {
        rps.add(new JsonPrimitive(rp));
    }/*from w ww . j a  v  a 2  s  .co  m*/
    return rps;
}

From source file:com.bekwam.resignator.model.ConfigurationJSONAdapter.java

License:Apache License

private JsonArray serializeProfiles(List<Profile> profiles) {
    JsonArray ps = new JsonArray();

    for (Profile p : profiles) {

        JsonObject profileObj = new JsonObject();

        profileObj.addProperty("profileName", p.getProfileName());
        profileObj.addProperty("replaceSignatures", p.getReplaceSignatures());
        profileObj.addProperty("argsType", String.valueOf(p.getArgsType()));

        if (p.getSourceFile().isPresent()) {
            SourceFile sf = p.getSourceFile().get();
            JsonObject sfObj = new JsonObject();
            sfObj.addProperty("fileName", sf.getFileName());
            profileObj.add("sourceFile", sfObj);
        }//  w  w  w . j a  va  2s.  c  o  m

        if (p.getTargetFile().isPresent()) {
            TargetFile tf = p.getTargetFile().get();
            JsonObject tfObj = new JsonObject();
            tfObj.addProperty("fileName", tf.getFileName());
            profileObj.add("targetFile", tfObj);
        }

        if (p.getJarsignerConfig().isPresent()) {
            JarsignerConfig jc = p.getJarsignerConfig().get();
            JsonObject jcObj = new JsonObject();
            jcObj.addProperty("alias", jc.getAlias());

            //
            // #1 storepass and keypass become temporary fields while the encrypted fields
            // are persisted
            //

            jcObj.addProperty("storepass", jc.getEncryptedStorepass());
            jcObj.addProperty("keypass", jc.getEncryptedKeypass());

            jcObj.addProperty("keystore", jc.getKeystore());
            jcObj.addProperty("verbose", jc.getVerbose());
            profileObj.add("jarsignerConfig", jcObj);
        }

        ps.add(profileObj);
    }

    return ps;
}

From source file:com.bhuwan.eventregistration.business.boundary.EventRegistrationResource.java

@GET
public Response getAllEventData() throws FileNotFoundException, IOException {
    String path = getClass().getClassLoader().getResource("/eventdata/").getPath();
    File eventDataDirectory = new File(path);
    String[] list = eventDataDirectory.list();
    JsonArray array = new JsonArray();
    for (String fileName : list) {
        array.add(new JsonParser().parse(FileUtils.readFileToString(Paths.get(path + fileName).toFile())));
    }//  w w w  .  j av a2s  . com
    return Response.ok(array.toString()).header("Access-Control-Allow-Origin", "*").build();
}