Package com.google.gson

Examples of com.google.gson.JsonArray


      try {
        while (true) {
          String solrQuery = buildCurrentSolrQuery(start, rows, fq);

          JsonArray docsJson = sendSearchRequest(solrQuery, extractDocsJsonFunction);

          addSearchResultsToCurrentWaveView(currentUserWavesView, docsJson);
          if (docsJson.size() < rows) {
            break;
          }
          start += rows;
        }
      } catch (Exception e) {
View Full Code Here


  }

  private static JsonArray extractDocsJson(InputStreamReader isr) {
    JsonObject json = new JsonParser().parse(isr).getAsJsonObject();
    JsonObject responseJson = json.getAsJsonObject("response");
    JsonArray docsJson = responseJson.getAsJsonArray("docs");
    return docsJson;
  }
View Full Code Here

  }

  private JsonArray sendSearchRequest(String solrQuery,
      Function<InputStreamReader, JsonArray> function) throws URIException, IOException,
      HttpException {
    JsonArray docsJson;
    GetMethod getMethod = new GetMethod();
    HttpClient httpClient = new HttpClient();
    try {
      getMethod.setURI(new URI(solrQuery, false));
      int statusCode = httpClient.executeMethod(getMethod);
View Full Code Here

  @Override
  public JsonElement serialize(EventMessageBundle src, Type typeOfSrc,
      JsonSerializationContext context) {
    JsonObject result = new JsonObject();

    JsonArray events = new JsonArray();
    for (Event event : src.getEvents()) {
      try {
        events.add(EventSerializer.serialize(event, context));
      } catch (EventSerializationException e) {
        throw new JsonParseException(e);
      }
    }
    result.add(EVENTS_TAG, events);
View Full Code Here

    for(Entry<String, BlipData> entry : blipDatas.entrySet()) {
      blips.put(entry.getKey(), Blip.deserialize(operationQueue, wavelet, entry.getValue()));
    }

    // Deserialize events.
    JsonArray eventsArray = jsonObj.get(EVENTS_TAG).getAsJsonArray();
    List<Event> events = new ArrayList<Event>(eventsArray.size());
    for (JsonElement element : eventsArray) {
      JsonObject eventObject = element.getAsJsonObject();
      try {
        events.add(EventSerializer.deserialize(wavelet, result, eventObject, context));
      } catch (EventSerializationException e) {
View Full Code Here

            } else if (entry.getKey().equals("lineage")) {
                lineage = entry.getValue().getAsString().split("\\.");
            } else if (entry.getKey().equals("parentName")) {
                parentName = entry.getValue().getAsString();
            } else if (entry.getKey().equals("fields")) {
                JsonArray fieldsJson = entry.getValue().getAsJsonArray();
                fields.clear();

                for (JsonElement fieldJson : fieldsJson) {
                    DataModelField field = DataModelField.parse(fieldJson);
                    fields.put(field.getName(), field);
                }
            } else if (entry.getKey().equals("constraints")) {
                JsonArray constraintsJson = entry.getValue().getAsJsonArray();

                for (JsonElement constraintJson : constraintsJson) {
                    DataModelConstraint constraint = DataModelConstraint.parse(constraintJson);
                    constraints.add(constraint);
                }
View Full Code Here

  @Timed
  private void updateIndex(ReadableWaveletData wavelet) throws IndexException {
    Preconditions.checkNotNull(wavelet);
    if (IdUtil.isConversationalId(wavelet.getWaveletId())) {
      JsonArray docsJson = buildJsonDoc(wavelet);
      postUpdateToSolr(wavelet, docsJson);
    }
  }
View Full Code Here

      postMethod.releaseConnection();
    }
  }

  JsonArray buildJsonDoc(ReadableWaveletData wavelet) {
    JsonArray docsJson = new JsonArray();

    String waveletId = wavelet.getWaveletId().serialise();
    String modified = Long.toString(wavelet.getLastModifiedTime());
    String creator = wavelet.getCreator().getAddress();

    for (String docName : wavelet.getDocumentIds()) {
      ReadableBlipData document = wavelet.getDocument(docName);

      if (!IdUtil.isBlipId(docName)) {
        continue;
      }

      Iterable<DocInitialization> ops = Lists.newArrayList(document.getContent().asOperation());
      String text = Snippets.collateTextForOps(ops, new Function<StringBuilder, Void>() {

        @Override
        public Void apply(StringBuilder resultBuilder) {
          resultBuilder.append("\n");
          return null;
        }

      });

      JsonArray participantsJson = new JsonArray();
      for (ParticipantId participant : wavelet.getParticipants()) {
        String participantAddress = participant.toString();
        participantsJson.add(new JsonPrimitive(participantAddress));
      }

      String id =
          JavaWaverefEncoder.encodeToUriPathSegment(WaveRef.of(wavelet.getWaveId(),
              wavelet.getWaveletId(), docName));
View Full Code Here

    if (Util.isEmptyOrWhitespace(jsonString)) {
      return Collections.emptyList();
    }

    // Parse incoming operations.
    JsonArray requestsAsJsonArray = null;

    JsonElement json = null;
    try {
      json = jsonParser.parse(jsonString);
    } catch (JsonParseException e) {
      throw new InvalidRequestException("Couldn't deserialize incoming operations: " +
          jsonString, null, e);
    }

    if (json.isJsonArray()) {
      requestsAsJsonArray = json.getAsJsonArray();
    } else {
      requestsAsJsonArray = new JsonArray();
      requestsAsJsonArray.add(json);
    }

    // Convert incoming operations into a list of JsonRpcRequest.
    ProtocolVersion protocolVersion = determineProtocolVersion(requestsAsJsonArray);
    PROTOCOL_VERSION_COUNTERS.get(protocolVersion).incrementAndGet();
    List<OperationRequest> requests = new ArrayList<OperationRequest>(requestsAsJsonArray.size());
    for (JsonElement requestAsJsonElement : requestsAsJsonArray) {
      validate(requestAsJsonElement);
      requests.add(getGson(protocolVersion).fromJson(requestAsJsonElement,
          OperationRequest.class));
    }
View Full Code Here

          || sourceMapRoot.has("names")) {
        throw new SourceMapParseException("Invalid map format");
      }

      SourceMapGeneratorV3 generator = new SourceMapGeneratorV3();
      JsonArray sections = sourceMapRoot.get("sections").getAsJsonArray();
      for (int i = 0, count = sections.size(); i < count; i++) {
        JsonObject section = sections.get(i).getAsJsonObject();
        if (section.has("map") && section.has("url")) {
          throw new SourceMapParseException(
              "Invalid map format: section may not have both 'map' and 'url'");
        }
        JsonObject offset = section.get("offset").getAsJsonObject();
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.