本文整理汇总了Java中javax.json.Json.createObjectBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java Json.createObjectBuilder方法的具体用法?Java Json.createObjectBuilder怎么用?Java Json.createObjectBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.Json
的用法示例。
在下文中一共展示了Json.createObjectBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOpen
import javax.json.Json; //导入方法依赖的package包/类
@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);
}
}
示例2: buildUserResponseObject
import javax.json.Json; //导入方法依赖的package包/类
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();
}
示例3: toJson
import javax.json.Json; //导入方法依赖的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();
}
示例4: save
import javax.json.Json; //导入方法依赖的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;
}
示例5: buildGroupResponseObject
import javax.json.Json; //导入方法依赖的package包/类
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();
}
示例6: getJson
import javax.json.Json; //导入方法依赖的package包/类
public String getJson() {
JsonObjectBuilder user = Json.createObjectBuilder();
if (id != null) {
user.add(JSON_KEY_USER_ID, id);
}
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);
user.add(JSON_KEY_USER_PASSWORD, password);
return user.build().toString();
}
示例7: openCircuits
import javax.json.Json; //导入方法依赖的package包/类
@GET
@Path("open-circuits")
public JsonObject openCircuits() {
JsonObjectBuilder retVal = Json.createObjectBuilder();
this.failedInvocations.
entrySet().
forEach(entry -> retVal.add(entry.getKey(),entry.getValue()));
return retVal.build();
}
示例8: build
import javax.json.Json; //导入方法依赖的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();
}
示例9: all
import javax.json.Json; //导入方法依赖的package包/类
@GET
public JsonObject all() {
JsonObjectBuilder result = Json.createObjectBuilder();
System.getenv().
entrySet().
forEach(e -> result.add(e.getKey(), e.getValue()));
return result.build();
}
示例10: toBuilder
import javax.json.Json; //导入方法依赖的package包/类
/** Converts a {@link JsonObject} to a {@JsonObjectBuilder}. */
public static JsonObjectBuilder toBuilder(JsonObject object) {
JsonObjectBuilder builder = Json.createObjectBuilder();
for (Entry<String, JsonValue> e : object.entrySet()) {
builder.add(e.getKey(), e.getValue());
}
return builder;
}
示例11: ExitJson
import javax.json.Json; //导入方法依赖的package包/类
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());
}
示例12: toResponse
import javax.json.Json; //导入方法依赖的package包/类
@Override
public Response toResponse(ConstraintViolationException exception) {
JsonArrayBuilder errors = Json.createArrayBuilder();
for (ConstraintViolation violation : exception.getConstraintViolations()) {
JsonObjectBuilder errMsg = Json.createObjectBuilder();
errMsg.add(extractInvalidPropName(violation), violation.getMessage());
errors.add(errMsg);
}
return Response.status(Response.Status.BAD_REQUEST).entity(errors.build().toString()).build();
}
示例13: addToCart
import javax.json.Json; //导入方法依赖的package包/类
public void addToCart(Book book, int quantity) {
Entity bookEntity = retrieveEntity(book.getUri());
JsonObjectBuilder properties = Json.createObjectBuilder();
properties.add("quantity", quantity);
Entity entity = entityMapper.encodeBook(book);
entity.getProperties().forEach(properties::add);
performAction(bookEntity, "add-to-cart", properties.build());
}
示例14: testTwitterPostMention
import javax.json.Json; //导入方法依赖的package包/类
/**
* Tests sending a twitter post and a direct notification. IMPORTANT: Before enabling this test,
* update the application's twitter related properties (default: CHANGE_ME) with valid values.
* These properties are located in the application's root pom.xml.
*/
// @Test
public void testTwitterPostMention() throws Exception {
// Post a message.
String userMention = "@" + twitterRecepientHandle;
JsonObjectBuilder content = Json.createObjectBuilder();
content.add(JSON_KEY_TWITTER_HANDLE, twitterRecepientHandle);
content.add(
JSON_KEY_MESSAGE,
"Merry Christmas "
+ userMention
+ "."
+ System.getProperty("line.separator")
+ "Jack D., Jane D. and James D. contributed $10,000 for your gift. A wishlist gift was ordered and mailed.");
JsonObjectBuilder notification = Json.createObjectBuilder();
notification.add(JSON_KEY_NOTIFICATION, content.build());
Response response =
processRequest(notificationServiceURL, "POST", notification.build().toString());
assertEquals(
"HTTP response code should have been " + Status.OK.getStatusCode() + ".",
Status.OK.getStatusCode(),
response.getStatus());
// Verify that the notification was logged.
BufferedReader br = new BufferedReader(new FileReader(logFile));
try {
String line = null;
while ((line = br.readLine()) != null) {
if (line.contains("Merry Christmas " + userMention)) {
return;
}
}
fail("Not all notifications were found.");
} finally {
br.close();
}
}
示例15: renameSensor
import javax.json.Json; //导入方法依赖的package包/类
public void renameSensor(int sensorId, String name) throws IOException {
if (name == null || name.trim().isEmpty()) {
return;
}
JsonObjectBuilder obj = Json.createObjectBuilder();
obj.add("name", name);
makeQuery(PUT, PROTOCOL + bridge.getIp() + API + "/" + bridge.getKey() + SENSORS + "/" + sensorId, obj.build().toString());
}