本文整理匯總了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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}