Package javax.json

Examples of javax.json.JsonObjectBuilder


    @Inject
    MonitoringAdmin admin;

    @POST
    public JsonObject startPolling(JsonObject pollingInfo) {
        JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
        int interval = pollingInfo.getInt(INTERVAL);
        configurator.setValue(INTERVAL, interval);
        String location = pollingInfo.getString(LOCATION, "localhost:4848");
        configurator.setValue(LOCATION, location);
        controller.restart();
View Full Code Here


    }

    @GET
    public JsonObject status() {
        JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
        Date nextTimeout = controller.nextTimeout();
        String timeoutAsString = "-";
        if (nextTimeout != null) {
            timeoutAsString = nextTimeout.toString();
        }
        objectBuilder.add("nextTimeout", timeoutAsString).add(INTERVAL, configurator.getValue(INTERVAL));
        return objectBuilder.build();
    }
View Full Code Here

    @Override
    @NotNull(message = "Gist can't be NULL")
    public Gist create(@NotNull(message = "list of files can't be NULL")
        final Map<String, String> files, final boolean visible
    ) throws IOException {
        JsonObjectBuilder builder = Json.createObjectBuilder();
        for (final Map.Entry<String, String> file : files.entrySet()) {
            builder = builder.add(
                file.getKey(),
                Json.createObjectBuilder().add("content", file.getValue())
            );
        }
        final JsonStructure json = Json.createObjectBuilder()
View Full Code Here

    public JsonArray filter(final JsonArray properties) {
        final JsonArrayBuilder documents = Json.createArrayBuilder();
        final List<JsonString> propertyList = properties.getValuesAs(JsonString.class);

        for (final JsonObject jsonObject : DocumentStorage.getAll()) {
            final JsonObjectBuilder documentBuilder = Json.createObjectBuilder();

            for (final JsonString property : propertyList) {
                final String key = property.getString();

                if (jsonObject.containsKey(key)) {
                    documentBuilder.add(key, jsonObject.get(key));
                }
            }

            final JsonObject document = documentBuilder.build();
            if (!document.isEmpty()) {
                documents.add(document);
            }
        }
View Full Code Here

  /* (non-Javadoc)
   * @see com.cloutree.modelevaluator.PredictiveModelResult#toJSON()
   */
  @Override
  public String toJSON() {
    JsonObjectBuilder builder = Json.createObjectBuilder();
   
    JsonArrayBuilder outputBuilder = Json.createArrayBuilder();
   
    // Output Values
    Set<String> outputKeys = this.outputValues.keySet();
    for(String outputKey : outputKeys) {
        Object val = this.outputValues.get(outputKey);
        if(val != null) {
      outputBuilder.add(Json.createObjectBuilder().add(outputKey, val.toString()));
        }
    }
    builder.add("outputValues", outputBuilder);
   
    JsonArrayBuilder predictedBuilder = Json.createArrayBuilder();
    Set<String> predictedKeys = this.predictedValues.keySet();
    for(String predictedKey : predictedKeys) {
        Object val = this.predictedValues.get(predictedKey);
        if(val != null) {
      predictedBuilder.add(Json.createObjectBuilder().add(predictedKey, val.toString()));
        }
    }
    builder.add("predictedValues", predictedBuilder);
   
    JsonArrayBuilder errorBuilder = Json.createArrayBuilder();
    for(String error : this.errors) {
        errorBuilder.add(error);
    }
    builder.add("errors", errorBuilder);
   
    JsonObject jsonObject = builder.build();
    return jsonObject.toString();

  }
View Full Code Here

        for (JsonValue o : objarr)
          obj.add(o);
      } else
        obj = Json.createArrayBuilder();

      JsonObjectBuilder objThisIter = Json.createObjectBuilder();
      for (Pair<E, Double> pat : chosenPatSorted) {
        JsonObjectBuilder o = Json.createObjectBuilder();
        JsonArrayBuilder pos = Json.createArrayBuilder();
        JsonArrayBuilder neg = Json.createArrayBuilder();
        JsonArrayBuilder unlab = Json.createArrayBuilder();

        for (String w : posWords.get(pat.first()))
          pos.add(w);
        for (String w : negWords.get(pat.first()))
          neg.add(w);
        for (String w : unlabWords.get(pat.first()))
          unlab.add(w);

        o.add("Positive", pos);
        o.add("Negative", neg);
        o.add("Unlabeled", unlab);
        o.add("Score", pat.second());

        objThisIter.add(pat.first().toStringSimple(), o);
      }
      obj.add(objThisIter.build());
View Full Code Here

        IOUtils.ensureDir(new File(constVars.outDir + "/" + constVars.identifier + "/" + label));

        if (constVars.writeMatchedTokensFiles) {

          String matchedtokensfilename = constVars.outDir + "/" + constVars.identifier + "/" + label + "/tokensmatchedpatterns" + ".json";
          JsonObjectBuilder pats = Json.createObjectBuilder();
          for (Entry<E, Collection<Triple<String, Integer, Integer>>> en : tokensMatchedPat.entrySet()) {
            CollectionValuedMap<String, Pair<Integer, Integer>> matchedStrs = new CollectionValuedMap<String, Pair<Integer, Integer>>();
            for (Triple<String, Integer, Integer> en2 : en.getValue()) {
              allMatchedSents.add(en2.first());
              matchedStrs.add(en2.first(), new Pair<Integer, Integer>(en2.second(), en2.third()));
            }

            JsonObjectBuilder senttokens = Json.createObjectBuilder();
            for (Entry<String, Collection<Pair<Integer, Integer>>> sen : matchedStrs.entrySet()) {
              JsonArrayBuilder obj = Json.createArrayBuilder();
              for (Pair<Integer, Integer> sen2 : sen.getValue()) {
                JsonArrayBuilder startend = Json.createArrayBuilder();
                startend.add(sen2.first());
                startend.add(sen2.second());
                obj.add(startend);
              }
              senttokens.add(sen.getKey(), obj);
            }
            pats.add(en.getKey().toStringSimple(), senttokens);
          }
          IOUtils.writeStringToFile(pats.build().toString(), matchedtokensfilename, "utf8");

          // Writing the sentence json file -- tokens for each sentence
          JsonObjectBuilder senttokens = Json.createObjectBuilder();
          for (String sentId : allMatchedSents) {
            JsonArrayBuilder sent = Json.createArrayBuilder();
            for (CoreLabel l : Data.sents.get(sentId)) {
              sent.add(l.word());
            }
            senttokens.add(sentId, sent);
          }
          String sentfilename = constVars.outDir + "/" + constVars.identifier + "/sentences" + ".json";
          IOUtils.writeStringToFile(senttokens.build().toString(), sentfilename, "utf8");
        }
      }

    }
View Full Code Here

        }
        JsonArrayBuilder objThisIter = Json.createArrayBuilder();

        for (String w : reasonForWords.firstKeySet()) {
          JsonObjectBuilder objinner = Json.createObjectBuilder();

          JsonArrayBuilder l = Json.createArrayBuilder();
          for (String w2 : reasonForWords.getCounter(w).keySet()) {
            l.add(w2);
          }
          JsonArrayBuilder pats = Json.createArrayBuilder();
          for (E p : wordsPatExtracted.getCounter(w)) {
            pats.add(p.toStringSimple());
          }
          objinner.add("reasonwords", l);
          objinner.add("patterns", pats);
          objinner.add("score", finalwords.getCount(w));
          objinner.add("entity", w);
          objThisIter.add(objinner.build());
        }
        obj.add(objThisIter);

        // Redwood.log(ConstantsAndVariables.minimaldebug, channelNameLogger,
        // "Writing justification at " + filename);
View Full Code Here

  @Override
  public String encode(NotificationMessage m) throws EncodeException {
    StringWriter swriter = new StringWriter();
    try (JsonWriter jsonWrite = Json.createWriter(swriter)) {
      JsonObjectBuilder builder = Json.createObjectBuilder();
      builder.add("type", m.getType().toString()).
        add("adocId", m.getAdocId()).
        add(
          "data",
          Json.createObjectBuilder()
          .add("nbConnected", m.getNbConnected())
           .add("nbWriters", m.getWriters().size())
          .add("writers", toJSON(m.getWriters())));

      jsonWrite.writeObject(builder.build());
    }
    return swriter.toString();
  }
View Full Code Here

    }
    return swriter.toString();
  }
 
  private JsonObjectBuilder toJSON(Set<String> writers){
    JsonObjectBuilder jsb = Json.createObjectBuilder();
    for(String writer : writers){
      jsb.add(writer,writer);
    }
    return jsb;
   
  }
View Full Code Here

TOP

Related Classes of javax.json.JsonObjectBuilder

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.