Java 类javax.json.JsonObjectBuilder 实例源码

项目:poi-visualizer    文件:OLEDirEntry.java   
@Override
protected void setProperties() {
    final DirectoryNode dirNode = (DirectoryNode)entry;

    final JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
    ClassID storageClsid = dirNode.getStorageClsid();
    if (storageClsid == null) {
        jsonBuilder.addNull("storage_clsid");
    } else {
        jsonBuilder.add("storage_clsid", storageClsid.toString());
    }

    dirNode.forEach(e -> {
        if (e instanceof DocumentNode) {
            DocumentNode dn = (DocumentNode)e;
            jsonBuilder.add(escapeString(dn.getName()), "Size: "+dn.getSize());
        }
    });

    final String props = jsonBuilder.build().toString();
    if (surrugateEntry != null) {
        treeObservable.mergeProperties(props);
    } else {
        treeObservable.setProperties(props);
    }
}
项目:sample-acmegifts    文件:OccasionResource.java   
Response buildPostRunResponse(OccasionResponse occasionResponse) {

    Throwable notificationThrowable = occasionResponse.getNotificationThrowable();
    String requestResponse = occasionResponse.getNotificationType();
    if (notificationThrowable != null) {
      logger.fine("Throwable message: " + notificationThrowable.getMessage());
    }
    JsonBuilderFactory factory = Json.createBuilderFactory(null);
    JsonObjectBuilder builder = factory.createObjectBuilder();
    JsonObject responseBody = null;
    if (requestResponse.equals(OccasionResponse.NOTIFICATION_TYPE_LOG)
        || requestResponse.equals(OccasionResponse.NOTIFICATION_TYPE_TWEET)) {
      responseBody = builder.add(JSON_KEY_OCCASION_POST_RUN_SUCCESS, requestResponse).build();
    } else {
      responseBody = builder.add(JSON_KEY_OCCASION_POST_RUN_ERROR, requestResponse).build();
    }
    return Response.ok(responseBody, MediaType.APPLICATION_JSON).build();
  }
项目:poi-visualizer    文件:TreeObservable.java   
public void mergeProperties(final String properties) {
    if (StringUtils.isEmpty(properties)) {
        return;
    }

    if (StringUtils.isEmpty(getProperties())) {
        setProperties(properties);
        return;
    }

    final JsonReaderFactory fact = Json.createReaderFactory(null);
    final JsonReader r1 = fact.createReader(new StringReader(getProperties()));
    final JsonObjectBuilder jbf = Json.createObjectBuilder(r1.readObject());

    final JsonReader r2 = fact.createReader(new StringReader(getProperties()));
    final JsonObject obj2 = r2.readObject();

    for (Entry<String, JsonValue> jv : obj2.entrySet()) {
        jbf.add(jv.getKey(), jv.getValue());
    }

    setProperties(jbf.build().toString());
}
项目:launcher-backend    文件:MissionControlStatusEndpoint.java   
@OnOpen
public void onOpen(Session session, @PathParam("uuid") String uuid) {
    UUID key = UUID.fromString(uuid);
    peers.put(key, session);
    JsonArrayBuilder builder = Json.createArrayBuilder();
    for (StatusEventType statusEventType : StatusEventType.values()) {
        JsonObjectBuilder object = Json.createObjectBuilder();
        builder.add(object.add(statusEventType.name(), statusEventType.getMessage()).build());
    }

    RemoteEndpoint.Async asyncRemote = session.getAsyncRemote();
    asyncRemote.sendText(builder.build().toString());
    // Send pending messages
    List<String> messages = messageBuffer.remove(key);
    if (messages != null) {
        messages.forEach(asyncRemote::sendText);
    }
}
项目:trellis    文件:MultipartUploader.java   
/**
 *  Add a segment of a binary.
 *
 *  <p>Note: the response will be a json structure, such as:</p>
 *  <pre>{
 *    "digest": "a-hash"
 *  }</pre>
 *
 *  @param id the upload session identifier
 *  @param partNumber the part number
 *  @param part the input stream
 *  @return a response
 */
@PUT
@Timed
@Path("{partNumber}")
@Produces("application/json")
public String uploadPart(@PathParam("id") final String id,
        @PathParam("partNumber") final Integer partNumber,
        final InputStream part) {

    final JsonObjectBuilder builder = Json.createObjectBuilder();

    if (!binaryService.uploadSessionExists(id)) {
        throw new NotFoundException();
    }

    final String digest = binaryService.uploadPart(id, partNumber, part);

    return builder.add("digest", digest).build().toString();
}
项目:NGSI-LD_Wrapper    文件:JsonUtilities.java   
public static void addValue(JsonObjectBuilder obj, String key, Object value) {
    if (value instanceof Integer) {
        obj.add(key, (Integer)value);
    }
    else if (value instanceof String) {
        obj.add(key, (String)value);
    }
    else if (value instanceof Float) {
        obj.add(key, (Float)value);
    }
    else if (value instanceof Double) {
        obj.add(key, (Double)value);
    }
    else if (value instanceof Boolean) {
        obj.add(key, (Boolean)value);
    }
    else if (value instanceof JsonValue) {
        JsonValue val = (JsonValue)value;
        obj.add(key, val);
    }
    // Add more cases here
}
项目:KITE    文件:TestManager.java   
/**
 * Develops meta json object. See developResult() above for details.
 * <p>
 * Sample output: {"totalTests": 1, "lastTest":true}} where; totalTests would be part of the first
 * result while lastTest would be part of the last result from the batch.
 *
 * @return JsonObjectBuilder
 */
private JsonObjectBuilder getMeta(boolean withBrowserList) {
  JsonObjectBuilder jsonObjectBuilder = null;

  if (this.isFirstTest()) {
    if (jsonObjectBuilder == null)
      jsonObjectBuilder = Json.createObjectBuilder();
    jsonObjectBuilder.add("totalTests", this.totalTests);
    if (withBrowserList)
      jsonObjectBuilder.add("browsers", Configurator.getInstance().getBrowserListJsonArray())
              .add("description",this.testConf.getDescription());
  }

  if (this.isLastTest) {
    if (jsonObjectBuilder == null)
      jsonObjectBuilder = Json.createObjectBuilder();
    jsonObjectBuilder.add("lastTest", this.isLastTest);
  }

  return jsonObjectBuilder;
}
项目:KITE    文件:RTCMediaStreamTrackStats.java   
@Override
public JsonObjectBuilder getJsonObjectBuilder() {
    JsonObjectBuilder jsonObjectBuilder =
            Json.createObjectBuilder()
                    .add("trackIdentifier", this.trackIdentifier)
                    .add("remoteSource", this.remoteSource)
                    .add("ended", this.ended)
                    .add("detached", this.detached)
                    .add("frameWidth", this.frameWidth)
                    .add("frameHeight", this.frameHeight)
                    .add("framesPerSecond", this.framesPerSecond)
                    .add("framesSent", this.framesSent)
                    .add("framesReceived", this.framesReceived)
                    .add("frameHeight", this.frameHeight)
                    .add("framesDecoded", this.framesDecoded)
                    .add("framesDropped", this.framesDropped)
                    .add("framesCorrupted", this.framesCorrupted)
                    .add("audioLevel", this.audioLevel);

    return jsonObjectBuilder;
}
项目:KITE    文件:RTCRTPStreamStats.java   
@Override
public JsonObjectBuilder getJsonObjectBuilder() {
    JsonObjectBuilder jsonObjectBuilder =
            Json.createObjectBuilder()
                    .add("ssrc", this.ssrc)
                    .add("mediaType", this.mediaType)
                    .add("trackId", this.trackId)
                    .add("transportId", this.transportId)
                    .add("nackCount", this.nackCount)
                    .add("codecId", this.codecId);
    if (this.inbound)
        jsonObjectBuilder.add("packetsReceived", Utility.getStatByName(this.statObject, "packetsReceived"))
                .add("bytesReceived", Utility.getStatByName(this.statObject, "bytesReceived"))
                .add("packetsLost", Utility.getStatByName(this.statObject, "packetsLost"))
                .add("packetsDiscarded", Utility.getStatByName(this.statObject, "packetsDiscarded"))
                .add("jitter", Utility.getStatByName(this.statObject, "jitter"))
                .add("remoteId", Utility.getStatByName(this.statObject, "remoteId"))
                .add("framesDecoded", Utility.getStatByName(this.statObject, "framesDecoded"));
    else
        jsonObjectBuilder.add("packetsSent", Utility.getStatByName(this.statObject, "packetsSent"))
                .add("bytesSent", Utility.getStatByName(this.statObject, "bytesSent"))
                .add("remoteId", Utility.getStatByName(this.statObject, "remoteId"))
                .add("framesDecoded", Utility.getStatByName(this.statObject, "framesDecoded"));

    return jsonObjectBuilder;
}
项目:KITE    文件:RTCIceCandidatePairStats.java   
@Override
public JsonObjectBuilder getJsonObjectBuilder() {
    JsonObjectBuilder jsonObjectBuilder =
            Json.createObjectBuilder()
                    .add("transportId", this.transportId)
                    .add("localCandidateId", this.localCandidateId)
                    .add("remoteCandidateId", this.remoteCandidateId)
                    .add("state", this.state)
                    .add("priority", this.priority)
                    .add("nominated", this.nominated)
                    .add("bytesSent", this.bytesSent)
                    .add("currentRoundTripTime", this.currentRoundTripTime)
                    .add("totalRoundTripTime", this.totalRoundTripTime)
                    .add("bytesReceived", this.bytesReceived);
    return jsonObjectBuilder;
}
项目:KITE    文件:GetUpdateTest.java   
@Override
public Object testScript() throws Exception {
    String result = "";
    webDriver = this.getWebDriverList().get(0);
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    for (String target: subjectList.keySet()){
        subject = target;
        this.takeAction();
        result = this.testJavaScript();
        subjectList.replace(target,result);
        jsonObjectBuilder.add(target, result);
    }
    JsonObject payload = jsonObjectBuilder.build();
    if (logger.isInfoEnabled())
      logger.info(payload.toString());
    return payload.toString();
}
项目:sample-acmegifts    文件:NotificationRetryBean.java   
@Retry(maxRetries = 2)
@Fallback(NotificationFallbackHandler.class)
public OccasionResponse makeNotificationConnection(
    String message,
    Orchestrator orchestrator,
    String jwtTokenString,
    String notification11ServiceUrl,
    String twitterHandle,
    String notificationServiceUrl)
    throws IOException {

  JsonBuilderFactory factory = Json.createBuilderFactory(null);
  JsonObjectBuilder builder = factory.createObjectBuilder();
  JsonObject notificationRequestPayload = builder.add(JSON_KEY_NOTIFICATION, message).build();
  Response notificationResponse =
      orchestrator.makeConnection(
          "POST", notificationServiceUrl, notificationRequestPayload.toString(), jwtTokenString);
  OccasionResponse occasionResponse =
      new OccasionResponse(notificationResponse, OccasionResponse.NOTIFICATION_TYPE_LOG, null);

  return occasionResponse;
}
项目:sample-acmegifts    文件:OrchestratorResourceMockTest.java   
private String buildGroupResponseObject(String name, String[] members, String[] occasions) {
  JsonObjectBuilder group = Json.createObjectBuilder();
  group.add(JSON_KEY_GROUP_NAME, name);

  JsonArrayBuilder membersArray = Json.createArrayBuilder();
  for (int i = 0; i < members.length; i++) {
    membersArray.add(members[i]);
  }
  group.add(JSON_KEY_MEMBERS_LIST, membersArray.build());

  JsonArrayBuilder occasionsArray = Json.createArrayBuilder();
  for (int i = 0; i < occasions.length; i++) {
    occasionsArray.add(occasions[i]);
  }
  group.add(JSON_KEY_OCCASIONS_LIST, occasionsArray.build());

  return group.build().toString();
}
项目:sample-acmegifts    文件:OrchestratorResourceMockTest.java   
private String buildUserResponseObject(
    String firstName,
    String lastName,
    String userName,
    String twitterHandle,
    String wishListLink,
    String[] groups) {
  JsonObjectBuilder user = Json.createObjectBuilder();
  user.add(JSON_KEY_USER_FIRST_NAME, firstName);
  user.add(JSON_KEY_USER_LAST_NAME, lastName);
  user.add(JSON_KEY_USER_NAME, userName);
  user.add(JSON_KEY_USER_TWITTER_HANDLE, twitterHandle);
  user.add(JSON_KEY_USER_WISH_LIST_LINK, wishListLink);

  JsonArrayBuilder groupArray = Json.createArrayBuilder();
  for (int i = 0; i < groups.length; i++) {
    groupArray.add(groups[i]);
  }
  user.add(JSON_KEY_USER_GROUPS, groupArray.build());

  return user.build().toString();
}
项目:sample-acmegifts    文件:Group.java   
/**
 * Create a JSON string based on the content of this group
 *
 * @return The JSON string with the content of this group
 */
public String getJson() {
  JsonObjectBuilder group = Json.createObjectBuilder();
  if (id != null) {
    group.add(JSON_KEY_GROUP_ID, id);
  }

  group.add(JSON_KEY_GROUP_NAME, name);

  JsonArrayBuilder membersArray = Json.createArrayBuilder();
  for (int i = 0; i < members.length; i++) {
    membersArray.add(members[i]);
  }
  group.add(JSON_KEY_MEMBERS_LIST, membersArray.build());

  return group.build().toString();
}
项目:bluemix-liberty-microprofile-demo    文件:ReservationJsonAdapter.java   
@Override
public JsonObject toJson(Reservation reservation) {
    Objects.requireNonNull(reservation, RESERVATION_ISNT_ALLOWED_TO_BE_NULL);
    JsonObjectBuilder builder = Json.createObjectBuilder();
       if (reservation.getId() != null)
           builder = builder.add("id", reservation.getId());
       if (reservation.getVenue() != null)
        builder = builder.add("venue", reservation.getVenue());
       if (reservation.getReservedBy() != null)
        builder = builder.add("reservedBy", reservation.getReservedBy());
       if (reservation.getDate() != null)           
        builder = builder.add("date", format(reservation.getDate()));
       if (reservation.getStartTime() != null)
        builder = builder.add("startAt", format(reservation.getStartTime()));
       if (reservation.getDuration() != null)
           builder = builder.add("duration", format(reservation.getDuration()));
       return builder.build();
}
项目:poi    文件:ExampleStore.java   
public JsonObject save(JsonObject input, String href, String date) {

        String id = href.substring(href.lastIndexOf('/') +1);

        JsonObjectBuilder builder = Json.createObjectBuilder();
        builder.add("id", id);
        builder.add("date", date);

        JsonObject jsonLink = Json.createObjectBuilder()
                .add("rel", Json.createArrayBuilder().add("self").build())
                .add("href", href)
                .build();
        builder.add("links", jsonLink);

        for (Map.Entry<String, JsonValue> entry : input.entrySet()) {
            builder.add(entry.getKey(), entry.getValue());
        }

        JsonObject storedObject = builder.build();
        exampleStore.put(id, storedObject);

        return storedObject;
    }
项目:poi-visualizer    文件:OPCRootEntry.java   
@Override
protected void setProperties() {
    try {
        final PackageProperties props = opcPackage.getPackageProperties();

        final Object[][] values = {
                { "category", props.getCategoryProperty() },
                { "contentStatus", props.getContentStatusProperty() },
                { "contentType", props.getContentTypeProperty() },
                { "creator", props.getCreatorProperty() },
                { "description", props.getDescriptionProperty() },
                { "identifier", props.getIdentifierProperty() },
                { "keywords", props.getKeywordsProperty() },
                { "language", props.getLanguageProperty() },
                { "lastModifiedBy", props.getLastModifiedByProperty() },
                { "revision", props.getRevisionProperty() },
                { "subject", props.getSubjectProperty() },
                { "title", props.getTitleProperty() },
                { "version", props.getVersionProperty() },
                { "created", props.getCreatedProperty() },
                { "modified", props.getModifiedProperty() },
        };

        final JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
        for (Object[] v : values) {
            final Nullable<?> nValue = (Nullable<?>)v[1];
            if (nValue.hasValue()) {
                Object val = nValue.getValue();
                if (val instanceof Date) {
                    val = DATE_FMT.format((Date)val);
                }
                jsonBuilder.add((String)v[0], val.toString());
            }
        }

        treeObservable.mergeProperties(jsonBuilder.build().toString());
    } catch (InvalidFormatException e) {
        treeObservable.mergeProperties(null);
    }
}
项目:versioneye-api    文件:MkStorage.java   
@Override
public Storage add(
    final String name, final JsonObjectBuilder builder
) {
    this.values.put(name, builder.build());
    return this;
}
项目:versioneye-api    文件:MkStorage.java   
@Override
public JsonObject build() {
    final JsonObjectBuilder builder = Json.createObjectBuilder();
    for(final Entry<String, Object> pair : this.values.entrySet()) {
        this.addToBuilder(pair, builder);
    }
    return builder.build();
}
项目:versioneye-api    文件:MkStorage.java   
/**
 * Add an entry from the map to the given {@link JsonObjectBuilder}.
 * @param pair Map entry.
 * @param builder JsonObjectBuilder
 * @checkstyle NPathComplexity (50 lines)
 */
private void addToBuilder(
    final Entry<String, Object> pair, final JsonObjectBuilder builder
) {
    if(pair.getValue() instanceof JsonValue) {
        builder.add(pair.getKey(), (JsonValue) pair.getValue());
    }
    if(pair.getValue() instanceof String) {
        builder.add(pair.getKey(), (String) pair.getValue());
    }
    if(pair.getValue() instanceof Boolean) {
        builder.add(pair.getKey(), (Boolean) pair.getValue());
    }
    if(pair.getValue() instanceof Integer) {
        builder.add(pair.getKey(), (Integer) pair.getValue());
    }
    if(pair.getValue() instanceof Long) {
        builder.add(pair.getKey(), (Long) pair.getValue());
    }
    if(pair.getValue() instanceof Double) {
        builder.add(pair.getKey(), (Double) pair.getValue());
    }
    if(pair.getValue() instanceof BigInteger) {
        builder.add(pair.getKey(), (BigInteger) pair.getValue());
    }
    if(pair.getValue() instanceof BigDecimal) {
        builder.add(pair.getKey(), (BigDecimal) pair.getValue());
    }
}
项目:launcher-backend    文件:JsonOperations.java   
public static JsonObject exceptionToJson(Throwable e, int depth) {
    JsonArrayBuilder stackElements = createArrayBuilder();
    StackTraceElement[] stackTrace = e.getStackTrace();
    JsonObjectBuilder builder = createObjectBuilder()
            .add("type", e.getClass().getName());

    add(builder, "message", e.getMessage());
    add(builder, "localizedMessage", e.getLocalizedMessage());
    add(builder, "forgeVersion", Versions.getImplementationVersionFor(UIContext.class).toString());

    if (stackTrace != null) {
        for (StackTraceElement element : stackTrace) {
            stackElements.add(stackTraceElementToJson(element));
        }
        builder.add("stackTrace", stackElements);
    }

    if (depth > 0) {
        Throwable cause = e.getCause();
        if (cause != null && cause != e) {
            builder.add("cause", exceptionToJson(cause, depth - 1));
        }
    }
    if (e instanceof WebApplicationException) {
        WebApplicationException webApplicationException = (WebApplicationException) e;
        Response response = webApplicationException.getResponse();
        if (response != null) {
            builder.add("status", response.getStatus());
        }
    }
    return builder.build();
}
项目:launcher-backend    文件:JsonOperations.java   
public static Object unwrapJsonObjects(Object entity) {
    if (entity instanceof JsonObjectBuilder) {
        JsonObjectBuilder jsonObjectBuilder = (JsonObjectBuilder) entity;
        entity = jsonObjectBuilder.build();
    }
    if (entity instanceof JsonStructure) {
        StringWriter buffer = new StringWriter();
        JsonWriter writer = Json.createWriter(buffer);
        writer.write((JsonStructure) entity);
        writer.close();
        return buffer.toString();
    }
    return entity;
}
项目:launcher-backend    文件:JsonOperations.java   
private static JsonObjectBuilder stackTraceElementToJson(StackTraceElement element) {
    JsonObjectBuilder builder = createObjectBuilder().add("line", element.getLineNumber());
    add(builder, "class", element.getClassName());
    add(builder, "file", element.getFileName());
    add(builder, "method", element.getMethodName());
    return builder;
}
项目:launcher-backend    文件:JsonBuilder.java   
public JsonBuilder addInput(String name, List<String> value) {
    JsonObjectBuilder objectBuilder = factory.createObjectBuilder();
    objectBuilder.add("name", name);

    if (value.size() == 1) {
        objectBuilder.add("value", value.get(0));
    } else {
        JsonArrayBuilder valueArrayBuilder = factory.createArrayBuilder();
        value.forEach(valueArrayBuilder::add);
        objectBuilder.add("value", valueArrayBuilder);
    }

    arrayBuilder.add(objectBuilder);
    return this;
}
项目:launcher-backend    文件:JsonBuilder.java   
public JsonObject build() {
    JsonObjectBuilder jsonObjectBuilder = factory.createObjectBuilder();
    jsonObjectBuilder.add("inputs", arrayBuilder);
    jsonObjectBuilder.add("stepIndex", stepIndex);

    return jsonObjectBuilder.build();
}
项目:launcher-backend    文件:LaunchResource.java   
@GET
@javax.ws.rs.Path("/commands/{commandName}")
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getCommandInfo(
        @PathParam("commandName") @DefaultValue(DEFAULT_COMMAND_NAME) String commandName,
        @Context HttpHeaders headers)
        throws Exception {
    validateCommand(commandName);
    JsonObjectBuilder builder = createObjectBuilder();
    try (CommandController controller = getCommand(commandName, ForgeInitializer.getRoot(), headers)) {
        helper.describeController(builder, controller);
    }
    return builder.build();
}
项目:launcher-backend    文件:LaunchResource.java   
@POST
@javax.ws.rs.Path("/commands/{commandName}/validate")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JsonObject validateCommand(JsonObject content,
                                  @PathParam("commandName") @DefaultValue(DEFAULT_COMMAND_NAME) String commandName,
                                  @Context HttpHeaders headers)
        throws Exception {
    validateCommand(commandName);
    JsonObjectBuilder builder = createObjectBuilder();
    try (CommandController controller = getCommand(commandName, ForgeInitializer.getRoot(), headers)) {
        controller.getContext().getAttributeMap().put("action", "validate");
        helper.populateController(content, controller);
        int stepIndex = content.getInt("stepIndex", 1);
        if (controller instanceof WizardCommandController) {
            WizardCommandController wizardController = (WizardCommandController) controller;
            for (int i = 0; i < stepIndex; i++) {
                wizardController.next().initialize();
                helper.populateController(content, wizardController);
            }
        }
        helper.describeValidation(builder, controller);
        helper.describeInputs(builder, controller);
        helper.describeCurrentState(builder, controller);
    }
    return builder.build();
}
项目:launcher-backend    文件:LaunchResource.java   
@POST
@javax.ws.rs.Path("/commands/{commandName}/next")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public JsonObject nextStep(JsonObject content,
                           @PathParam("commandName") @DefaultValue(DEFAULT_COMMAND_NAME) String commandName,
                           @Context HttpHeaders headers)
        throws Exception {
    validateCommand(commandName);
    int stepIndex = content.getInt("stepIndex", 1);
    JsonObjectBuilder builder = createObjectBuilder();
    try (CommandController controller = getCommand(commandName, ForgeInitializer.getRoot(), headers)) {
        if (!(controller instanceof WizardCommandController)) {
            throw new WebApplicationException("Controller is not a wizard", Status.BAD_REQUEST);
        }
        controller.getContext().getAttributeMap().put("action", "next");
        WizardCommandController wizardController = (WizardCommandController) controller;
        helper.populateController(content, controller);
        for (int i = 0; i < stepIndex; i++) {
            wizardController.next().initialize();
            helper.populateController(content, wizardController);
        }
        helper.describeMetadata(builder, controller);
        helper.describeInputs(builder, controller);
        helper.describeCurrentState(builder, controller);
    }
    return builder.build();
}
项目:inbox    文件:MessagesResource.java   
private JsonObject formatList(JsonArray arr){
    JsonObject response;
    JsonObjectBuilder b = Json.createObjectBuilder();
    b.add("@context", CONTEXT);
    b.add("@type", TYPE);
    b.add("@id", ID_ROOT+"?target="+TARGET);
    b.add("contains",arr);
    response = b.build();
    return response;
}
项目:inbox    文件:Message.java   
/**
 *
 * @param source
 * @param key
 * @param value
 * @return
 */
public JsonObject generate(JsonObject source, String key, String value) {
    JsonObjectBuilder builder = Json.createObjectBuilder();
    builder.add(key, value);
    source.entrySet().
            forEach((Map.Entry<String, JsonValue> e) -> {
                builder.add(e.getKey(), e.getValue());
            });
    return builder.build();
}
项目:trellis    文件:MultipartUploader.java   
/**
 * Get a list of the uploads.
 *
 * <p>Note: the response structure will be like this:</p>
 * <pre>{
 *   "1": "somehash",
 *   "2": "otherhash",
 *   "3": "anotherhash"
 * }</pre>
 *
 * @param id the upload id
 * @return a response
 */
@GET
@Timed
@Produces("application/json")
public String listUploads(@PathParam("id") final String id) {
    final JsonObjectBuilder builder = Json.createObjectBuilder();

    if (!binaryService.uploadSessionExists(id)) {
        throw new NotFoundException();
    }
    binaryService.listParts(id).forEach(x -> builder.add(x.getKey().toString(), x.getValue()));

    return builder.build().toString();
}
项目:AccessConverter    文件:AccessConverter.java   
public static void ExitJson(boolean pretyPrint) {
    JsonObjectBuilder json = Json.createObjectBuilder();

    if(result.length() == 0)
        result = "fail";

    json.add("result", result);
    if(outputFile != null)
        json.add("outputFile", outputFile.getAbsolutePath());

    if(logFile != null)
        json.add("logFile", logFile.getAbsolutePath());

    if(zipFile != null && zipFile.exists())
        json.add("zipFile", zipFile.getAbsolutePath());

    if(pretyPrint) {
        Map<String, Object> properties = new HashMap<>(1);
        properties.put(JsonGenerator.PRETTY_PRINTING, true);
        StringWriter stringWriter = new StringWriter();
        try (JsonWriter jsonWriter = Json.createWriterFactory(properties).createWriter(stringWriter)) {
            jsonWriter.write(json.build());
        }

        System.out.println(stringWriter.toString());
    } else         
        System.out.print(json.build().toString());
}
项目:AccessConverter    文件:AccessConverter.java   
@Override
public JsonObjectBuilder toJsonObject() {
    JsonObjectBuilder json = super.toJsonObject();
    if(exception != null)
        json.add("exception", exception.toString());
    return json;
}
项目:hustic    文件:GetResponseHandler.java   
private JsonObject getData(JsonObject responseJson) {
    JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();

    Set<Map.Entry<String, JsonValue>> entries = responseJson.getJsonObject("_source").entrySet();
    for (Map.Entry<String, JsonValue> entry : entries) {
        jsonBuilder.add(entry.getKey(), entry.getValue());
    }

    jsonBuilder.add("id", Json.createValue(responseJson.getString("_id")));

    return jsonBuilder.build();
}
项目:NGSI-LD_Wrapper    文件:CsourceResource.java   
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addCsource(String jsonPayload) {
    JsonReader reader = Json.createReader(new StringReader(jsonPayload));

    JsonObject obj = reader.readObject();

    JsonObjectBuilder builder = Json.createObjectBuilder();

    builder.add("id", obj.getString("id"));
    builder.add("type", obj.getString("type"));

    for(String key:obj.keySet()) {
        if (!key.equals("id") && !key.equals("type")) {
            JsonObjectBuilder valueBuilder = Json.createObjectBuilder();
            valueBuilder.add("value", obj.get(key));
            if (key.equals("location")) {
                valueBuilder.add("type", "geo:json");
            }
            builder.add(key, valueBuilder.build());
        }
    }

    NgsiClient client = new NgsiClient(Configuration.ORION_BROKER);

    return client.createEntity(builder.build());
}
项目:KITE    文件:TestManager.java   
/**
 * Develops result json object. See developResult() above for details.
 *
 * @param payload payload as String or JsonObjectBuilder.
 * @return JsonObjectBuilder
 */
private JsonObjectBuilder getResult(Object payload) {
  JsonObjectBuilder jsonObjectBuilder =
      Json.createObjectBuilder().add("timeTaken", this.timeTaken);
  if (payload instanceof JsonObjectBuilder)
    jsonObjectBuilder.add("payload", (JsonObjectBuilder) payload);
  else
    jsonObjectBuilder.add("payload", (String) payload);
  return jsonObjectBuilder;
}
项目:KITE    文件:RTCIceCandidateStats.java   
@Override
public JsonObjectBuilder getJsonObjectBuilder() {
    JsonObjectBuilder jsonObjectBuilder =
            Json.createObjectBuilder()
                    .add("ip", this.ip)
                    .add("port", this.port)
                    .add("protocol", this.protocol)
                    .add("candidateType", this.candidateType)
                    .add("priority", this.priority)
                    .add("url", this.url);
    return jsonObjectBuilder;
}
项目:KITE    文件:RTCPeerConnectionStats.java   
@Override
public JsonObjectBuilder getJsonObjectBuilder() {
    JsonObjectBuilder jsonObjectBuilder =
            Json.createObjectBuilder()
                    .add("dataChannelsOpened", this.dataChannelsOpened)
                    .add("dataChannelsClosed", this.dataChannelsClosed);
    return jsonObjectBuilder;
}
项目:KITE    文件:RTCTransportStats.java   
@Override
public JsonObjectBuilder getJsonObjectBuilder() {
    JsonObjectBuilder jsonObjectBuilder =
            Json.createObjectBuilder()
                    .add("rtcpTransportStatsId", this.rtcpTransportStatsId)
                    .add("selectedCandidatePairId", this.selectedCandidatePairId)
                    .add("localCertificateId", this.localCertificateId)
                    .add("remoteCertificateId", this.remoteCertificateId)
                    .add("bytesSent", this.bytesSent)
                    .add("bytesReceived", this.bytesReceived);
    return jsonObjectBuilder;
}