当前位置: 首页>>代码示例>>Java>>正文


Java JsonObjectBuilder.build方法代码示例

本文整理汇总了Java中javax.json.JsonObjectBuilder.build方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObjectBuilder.build方法的具体用法?Java JsonObjectBuilder.build怎么用?Java JsonObjectBuilder.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.json.JsonObjectBuilder的用法示例。


在下文中一共展示了JsonObjectBuilder.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
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;
    }
 
开发者ID:h2mch,项目名称:poi,代码行数:24,代码来源:ExampleStore.java

示例2: toJson

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@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();
}
 
开发者ID:samolisov,项目名称:bluemix-liberty-microprofile-demo,代码行数:19,代码来源:ReservationJsonAdapter.java

示例3: testScript

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@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();
}
 
开发者ID:webrtc,项目名称:KITE,代码行数:18,代码来源:GetUpdateTest.java

示例4: build

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@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();
}
 
开发者ID:decorators-squad,项目名称:versioneye-api,代码行数:9,代码来源:MkStorage.java

示例5: exceptionToJson

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
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();
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:33,代码来源:JsonOperations.java

示例6: toJson

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@Override
public JsonStructure toJson() {
    JsonObjectBuilder json = Json.createObjectBuilder()
            .add("number", number)
            .add("name", name());
    parent().ifPresent(parent -> json.add("parent_id", parent.id()));
    return json.build();
}
 
开发者ID:yaroska,项目名称:true_oop,代码行数:9,代码来源:H2Category.java

示例7: getCommandInfo

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@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();
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:15,代码来源:LaunchResource.java

示例8: createGroup

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response createGroup(JsonObject payload) {

  // Validate the JWT. At this point, anyone can create a group if they
  // have a valid JWT.
  try {
    validateJWT();
  } catch (JWTException jwte) {
    return Response.status(Status.UNAUTHORIZED)
        .type(MediaType.TEXT_PLAIN)
        .entity(jwte.getMessage())
        .build();
  }

  // Create a new group based on the payload information
  Group newGroup = new Group(payload);

  // Create a db object from the group content and insert it into the
  // collection
  BasicDBObject dbGroup = newGroup.getDBObject(false);
  getGroupCollection().insert(dbGroup);

  // Return the new group id
  JsonObjectBuilder responseBuilder = Json.createObjectBuilder();
  String groupId = dbGroup.getString(Group.DB_ID);
  responseBuilder.add(Group.JSON_KEY_GROUP_ID, groupId);

  JsonObject response = responseBuilder.build();
  return Response.ok(response, MediaType.APPLICATION_JSON).build();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:33,代码来源:GroupResource.java

示例9: formatList

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
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;
}
 
开发者ID:CenterForDigitalHumanities,项目名称:inbox,代码行数:11,代码来源:MessagesResource.java

示例10: generate

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
/**
 *
 * @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();
}
 
开发者ID:CenterForDigitalHumanities,项目名称:inbox,代码行数:17,代码来源:Message.java

示例11: toJsonString

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
public String toJsonString(){
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder()
            .add("connectionState",this.getState())
            .add("numberOfParticipants", this.getHeadCount());

    JsonObject result = jsonObjectBuilder.build();
    return result.toString();
}
 
开发者ID:webrtc,项目名称:KITE,代码行数:9,代码来源:JitsiTest.java

示例12: all

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@GET
public JsonObject all() {
    JsonObjectBuilder result = Json.createObjectBuilder();
    System.getenv().
            entrySet().
            forEach(e -> result.add(e.getKey(), e.getValue()));
    return result.build();
}
 
开发者ID:AdamBien,项目名称:javaee-calculator,代码行数:9,代码来源:ConfigurationResource.java

示例13: toJson

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
public JsonObject toJson() {
    JsonObjectBuilder builder = Json.createObjectBuilder()
            .add("timestamp", timestamp);
    valueAdder.accept(data, builder);
    if (dpTags != null && !dpTags.isEmpty()) {
        JsonObjectBuilder tags = Json.createObjectBuilder();
        dpTags.forEachPresent(tags::add);
        builder.add("tags", tags.build());
    }
    return builder.build();
}
 
开发者ID:jotak,项目名称:hawkular-java-toolbox,代码行数:12,代码来源:DataPoint.java

示例14: getLoyalty

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@GET
   @Path("/")
@Produces("application/json")
public JsonObject getLoyalty(@QueryParam("owner") String owner, @QueryParam("loyalty") String oldLoyalty, @QueryParam("total") double total) {
	JsonObjectBuilder loyaltyLevel = Json.createObjectBuilder();

	String loyalty = "Basic";
	if (total > 1000000.00) {
		loyalty = "Platinum";
	} else if (total > 100000.00) {
		loyalty = "Gold";
	} else if (total > 50000.00) {
		loyalty = "Silver";
	} else if (total > 10000.00) {
		loyalty = "Bronze";
	}

	if (!loyalty.equals(oldLoyalty)) try {
		JsonObjectBuilder builder = Json.createObjectBuilder();
		builder.add("owner", owner);
		builder.add("old", oldLoyalty);
		builder.add("new", loyalty);

		JsonObject message = builder.build();

		invokeJMS(message);
	} catch (JMSException jms) { //in case MQ is not configured, just log the exception and continue
		jms.printStackTrace();
		Exception linked = jms.getLinkedException();
		if (linked != null) linked.printStackTrace();
	} catch (Throwable t) { //in case MQ is not configured, just log the exception and continue
		t.printStackTrace();
	}

	loyaltyLevel.add("owner", owner);
	loyaltyLevel.add("loyalty", loyalty);
	return loyaltyLevel.build();
}
 
开发者ID:IBMStockTrader,项目名称:loyalty-level,代码行数:39,代码来源:LoyaltyLevel.java

示例15: getBeans

import javax.json.JsonObjectBuilder; //导入方法依赖的package包/类
@GET
public JsonObject getBeans() {
    final JsonObjectBuilder builder = Json.createObjectBuilder();
    queryService.getStoredBeans()
            .entrySet().forEach(e -> builder.add(e.getKey(), e.getValue()));
    return builder.build();
}
 
开发者ID:sdaschner,项目名称:scalable-coffee-shop,代码行数:8,代码来源:BeansResource.java


注:本文中的javax.json.JsonObjectBuilder.build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。