Package com.google.gson

Examples of com.google.gson.JsonArray


      System.out.println("ERROR: Request object did not contain function name");
    }
  }

  private void setHeaders(JsonElement headers) {
    JsonArray array_headers = JsonUtils.asJsonArray(headers);
    if (array_headers != null) {
      for (JsonElement jHeader : array_headers) {
        JsonObject header = JsonUtils.asJsonObject(jHeader);
        String name = header.get("name").getAsString();
        String value = header.get("value").getAsString();
View Full Code Here


      }
    }
  }

  private void setPostData(JsonElement jsonPostData) {
    JsonArray array_postDataParams = null;
    if(jsonPostData != null) array_postDataParams = JsonUtils.asJsonArray(jsonPostData);
   
    if (array_postDataParams != null) {
      for (JsonElement postParam : array_postDataParams) {
        JsonObject param = JsonUtils.asJsonObject(postParam);
View Full Code Here

      }
    }
  }

  private void setQueryString(JsonElement queryStringParams) {
    JsonArray array_params = JsonUtils.asJsonArray(queryStringParams);
    if (array_params != null) {
      for (JsonElement jQueryParam : array_params) {
        JsonObject queryParam = JsonUtils.asJsonObject(jQueryParam);
        String name = queryParam.get("name").getAsString();
        String value = queryParam.get("value").getAsString();
View Full Code Here

      topicsFile = TrecTemporalTopicSet.fromFile(new File(pathToTrecTopics));
    } catch (Exception e) {
      e.printStackTrace();
    }
   
    JsonArray outputJsonArray = new JsonArray();
    for(edu.illinois.lis.query.TrecTemporalTopic query : topicsFile) {
     

      JsonObject outputQueryObject = new JsonObject();
      outputQueryObject.addProperty("title", query.getId());
      outputQueryObject.addProperty("text", query.getQuery());
      outputQueryObject.addProperty("epoch", Double.toString(query.getEpoch()));
      outputQueryObject.addProperty("querytweettime", Long.toString(query.getQueryTweetTime()));
     
      String text = query.getQuery();
      String[] toks = text.split(" ");
     
      JsonArray modelArray = new JsonArray();
      for(String tok : toks) {
        JsonObject tupleObject = new JsonObject();
        tupleObject.addProperty("weight", 1.0);
        tupleObject.addProperty("feature", tok);
        modelArray.add(tupleObject);
      }
      outputQueryObject.add("model", modelArray);


      outputJsonArray.add(outputQueryObject);
View Full Code Here

      LOG.fatal("died reading queries from json file", e);
      System.exit(-1);
    }

   
    JsonArray queryObjectArray = obj.getAsJsonArray("queries");
    queryList = new ArrayList<GQuery>(queryObjectArray.size());
    nameToIndex = new HashMap<String,Integer>(queryList.size());
    Iterator<JsonElement> queryObjectIterator = queryObjectArray.iterator();
    int k=0;
    while(queryObjectIterator.hasNext()) {
      JsonObject queryObject = (JsonObject) queryObjectIterator.next();
      String title = queryObject.get("title").getAsString();
      String text  = queryObject.get("text").getAsString();
      double epoch = queryObject.get("epoch").getAsDouble();
      long querytweettime = queryObject.get("querytweettime").getAsLong();
      nameToIndex.put(title, k++);
      FeatureVector featureVector = new FeatureVector(null);
      JsonArray modelObjectArray = queryObject.getAsJsonArray("model");
      Iterator<JsonElement> featureIterator = modelObjectArray.iterator();
      while(featureIterator.hasNext()) {
        JsonObject featureObject = (JsonObject)featureIterator.next();
        double weight  = featureObject.get("weight").getAsDouble();
        String feature = featureObject.get("feature").getAsString();
        featureVector.addTerm(feature, weight);
View Full Code Here

    @Override
    public JsonElement serialize (PropertyMap src, Type typeOfSrc, JsonSerializationContext context) {
        JsonObject out = new JsonObject();
        for (String key : src.keySet()) {
            JsonArray jsa = new JsonArray();
            for (Property p : src.get(key)) {
                jsa.add(new JsonPrimitive(p.getValue()));
            }
            out.add(key, jsa);
        }
        return out;
    }
View Full Code Here

        writer.flush();
    }

    private static JsonObject analyzeBatch(BatchScript script) {
        assert script != null;
        JsonArray jobflows = new JsonArray();
        for (FlowScript flowScript : script.getAllFlows()) {
            JsonObject jobflow = analyzeJobflow(flowScript);
            jobflows.add(jobflow);
        }
        JsonObject batch = new JsonObject();
        batch.addProperty("id", script.getId());
        batch.add("jobflows", jobflows);
        return batch;
View Full Code Here

        return batch;
    }

    private static JsonObject analyzeJobflow(FlowScript flowScript) {
        assert flowScript != null;
        JsonArray phases = new JsonArray();
        for (Map.Entry<ExecutionPhase, Set<ExecutionScript>> entry : flowScript.getScripts().entrySet()) {
            ExecutionPhase phase = entry.getKey();
            if (entry.getValue().isEmpty() == false
                    || phase == ExecutionPhase.SETUP
                    || phase == ExecutionPhase.CLEANUP) {
                phases.add(new JsonPrimitive(phase.getSymbol()));
            }
        }
        JsonObject jobflow = new JsonObject();
        jobflow.addProperty("id", flowScript.getId());
        jobflow.add("blockers", toJsonArray(flowScript.getBlockerIds()));
View Full Code Here

        return jobflow;
    }

    private static JsonArray toJsonArray(Collection<String> values) {
        assert values != null;
        JsonArray array = new JsonArray();
        for (String value : values) {
            array.add(new JsonPrimitive(value));
        }
        return array;
    }
View Full Code Here

      if (input.getMeta() != null) {
         jsonTag.add("meta", new JsonParser().parse(new Gson().toJson(input.getMeta())));
      }

      if (input.getResources() != null && input.getResources().size() != 0) {
         JsonArray uuidsArray = new JsonArray();

         for (TagResource tagResource : input.getResources()) {
            uuidsArray.add(new JsonPrimitive(tagResource.getUuid()));
         }

         jsonTag.add("resources", uuidsArray);
      }
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.