Package com.google.gson

Examples of com.google.gson.JsonArray


    JsonElement element = new JsonParser().parse(json);

    JsonObject objElem = (JsonObject) valueReader.get(element, "object");
    assertEquals(objElem.get("subkey").getAsString(), "subvalue");

    JsonArray arrayElem = (JsonArray) valueReader.get(element, "array");
    assertEquals(Arrays.asList(arrayElem.get(0).getAsString(), arrayElem.get(1).getAsString()),
        Arrays.asList("elem1", "elem2"));

    assertEquals(valueReader.get(element, "boolean"), true);
    assertEquals(((Number) valueReader.get(element, "number")).intValue(), 55);
    assertEquals(valueReader.get(element, "string"), "foo");
View Full Code Here


        state.addProperty(CURRENT_VERSION, targetObject.getCurrentVersion());
        state.addProperty(IS_REGISTERED, Boolean.toString(targetObject.isRegistered()));
        state.addProperty(NEEDS_APPROVAL, Boolean.toString(targetObject.needsApprove()));
        state.addProperty(AUTO_APPROVE, Boolean.toString(targetObject.getAutoApprove()));

        JsonArray artifactsFromShop = new JsonArray();
        ArtifactObject[] artifactObjects = targetObject.getArtifactsFromShop();
        if (artifactObjects != null) {
            for (ArtifactObject a : artifactObjects) {
                artifactsFromShop.add(new JsonPrimitive(a.getDefinition()));
            }
        }
        state.add(ARTIFACTS_FROM_SHOP, artifactsFromShop);

        JsonArray artifactsFromDeployment = new JsonArray();
        DeploymentArtifact[] deploymentArtifacts = targetObject.getArtifactsFromDeployment();
        if (deploymentArtifacts != null) {
            for (DeploymentArtifact a : deploymentArtifacts) {
                artifactsFromDeployment.add(new JsonPrimitive(a.getUrl()));
            }
        }
        state.add(ARTIFACTS_FROM_DEPLOYMENT, artifactsFromDeployment);

        state.addProperty(LAST_INSTALL_VERSION, targetObject.getLastInstallVersion());
View Full Code Here

                return;
            }

            if (pathElements.length == 2) {
                // TODO this should be the current set of repository objects?!
                JsonArray result = new JsonArray();
                result.add(new JsonPrimitive(Workspace.ARTIFACT));
                result.add(new JsonPrimitive(Workspace.ARTIFACT2FEATURE));
                result.add(new JsonPrimitive(Workspace.FEATURE));
                result.add(new JsonPrimitive(Workspace.FEATURE2DISTRIBUTION));
                result.add(new JsonPrimitive(Workspace.DISTRIBUTION));
                result.add(new JsonPrimitive(Workspace.DISTRIBUTION2TARGET));
                result.add(new JsonPrimitive(Workspace.TARGET));
                resp.getWriter().println(m_gson.toJson(result));
                return;
            }
            else if (pathElements.length == 3) {
                listRepositoryObjects(workspace, pathElements[2], resp);
View Full Code Here

     */
    private void listRepositoryObjects(Workspace workspace, String entityType, HttpServletResponse resp) throws IOException {
        // TODO add a feature to filter the list that is returned (query, paging, ...)
        List<RepositoryObject> objects = workspace.getRepositoryObjects(entityType);

        JsonArray result = new JsonArray();
        for (RepositoryObject ro : objects) {
            String identity = ro.getDefinition();
            if (identity != null) {
                result.add(new JsonPrimitive(urlEncode(identity)));
            }
        }

        resp.getWriter().println(m_gson.toJson(result));
    }
View Full Code Here

         return route;
      }
   }

   private static JsonArray buildArrayOfStrings(Set<String> strings) {
      JsonArray array = new JsonArray();
      for (String string : strings) {
         array.add(new JsonPrimitive(string));
      }
      return array;
   }
View Full Code Here

              JsonParseException {
         Operation.Builder operationBuilder = ((Operation) context.deserialize(json,
                 OperationInternal.class)).toBuilder();
         JsonObject error = json.getAsJsonObject().getAsJsonObject("error");
         if (error != null) {
            JsonArray array = error.getAsJsonArray("errors");
            if (array != null) {
               for (JsonElement element : array) {
                  operationBuilder.addError((Operation.Error) context.deserialize(element, Operation.Error.class));
               }
            }
View Full Code Here

      public JsonElement serialize(InstanceTemplate src, Type typeOfSrc, JsonSerializationContext context) {
         InstanceTemplateInternal template = new InstanceTemplateInternal(src);
         JsonObject instance = (JsonObject) context.serialize(template, InstanceTemplateInternal.class);

         // deal with network
         JsonArray networkInterfaces = new JsonArray();
         for (InstanceTemplate.NetworkInterface networkInterface : template.getNetworkInterfaces()){
            networkInterfaces.add(context.serialize(networkInterface, InstanceTemplate.NetworkInterface.class));
         }
         instance.add("networkInterfaces", networkInterfaces);

         // deal with persistent disks
         if (src.getDisks() != null && !src.getDisks().isEmpty()) {
            JsonArray disks = new JsonArray();
            for (InstanceTemplate.PersistentDisk persistentDisk : src.getDisks()) {
               JsonObject disk = (JsonObject) context.serialize(persistentDisk, InstanceTemplate.PersistentDisk.class);
               disk.addProperty("type", "PERSISTENT");
               disks.add(disk);
            }
            instance.add("disks", disks);
         }

         // deal with metadata
View Full Code Here

              JsonParseException {
         Instance.Builder instanceBuilder = ((Instance) context.deserialize(json,
                 InstanceInternal.class)).toBuilder();
         JsonObject object = (JsonObject) json;
         if (object.get("disks") != null) {
            JsonArray disks = (JsonArray) object.get("disks");
            for (JsonElement element : disks) {
               JsonObject disk = (JsonObject) element;
               if (disk.get("type").getAsString().equals("PERSISTENT")) {
                  instanceBuilder.addDisk((Instance.PersistentAttachedDisk) context.deserialize(disk,
                          Instance.PersistentAttachedDisk.class));
View Full Code Here

      @Override
      public Metadata deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
              JsonParseException {
         ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
         JsonObject metadata = json.getAsJsonObject();
         JsonArray items = metadata.getAsJsonArray("items");
         if (items != null) {
            for (JsonElement element : items) {
               JsonObject object = element.getAsJsonObject();
               builder.put(object.get("key").getAsString(), object.get("value").getAsString());
            }
View Full Code Here

      @Override
      public JsonElement serialize(Metadata src, Type typeOfSrc, JsonSerializationContext context) {
         JsonObject metadataObject = new JsonObject();
         metadataObject.add("kind", new JsonPrimitive("compute#metadata"));
         JsonArray items = new JsonArray();
         for (Map.Entry<String, String> entry : src.getItems().entrySet()) {
            JsonObject object = new JsonObject();
            object.addProperty("key", entry.getKey());
            object.addProperty("value", entry.getValue());
            items.add(object);
         }
         metadataObject.add("items", items);
         if (src.getFingerprint() != null) {
            metadataObject.addProperty("fingerprint", src.getFingerprint());
         }
View Full Code Here

TOP

Related Classes of com.google.gson.JsonArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.