本文整理匯總了Java中javax.json.JsonObjectBuilder.add方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonObjectBuilder.add方法的具體用法?Java JsonObjectBuilder.add怎麽用?Java JsonObjectBuilder.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.json.JsonObjectBuilder
的用法示例。
在下文中一共展示了JsonObjectBuilder.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildGroupResponseObject
import javax.json.JsonObjectBuilder; //導入方法依賴的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();
}
示例2: getMeta
import javax.json.JsonObjectBuilder; //導入方法依賴的package包/類
/**
* 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;
}
示例3: getJson
import javax.json.JsonObjectBuilder; //導入方法依賴的package包/類
/**
* Create a JSON string based on the content of this group
*
* @return - A JSON string with the content of this group
*/
public String getJson() {
JsonObjectBuilder group = Json.createObjectBuilder();
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();
}
示例4: addValue
import javax.json.JsonObjectBuilder; //導入方法依賴的package包/類
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
}
示例5: setProperties
import javax.json.JsonObjectBuilder; //導入方法依賴的package包/類
@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);
}
}
示例6: testLoginNonSsl
import javax.json.JsonObjectBuilder; //導入方法依賴的package包/類
/** Tests login via the non-SSL port. The connection should be denied or forwarded. */
@Test
public void testLoginNonSsl() throws Exception {
// Add a user.
String loginAuthHeader =
"Bearer "
+ new JWTVerifier()
.createJWT("unauthenticated", new HashSet<String>(Arrays.asList("login")));
User user =
new User(null, "Niels", "Bohr", "nBohr", "@nBohr", "nBohrWishListLink", "myPassword");
Response response = processRequest(userServiceURL, "POST", user.getJson(), loginAuthHeader);
assertEquals(
"HTTP response code should have been " + Status.OK.getStatusCode() + ".",
Status.OK.getStatusCode(),
response.getStatus());
String authHeader = response.getHeaderString("Authorization");
new JWTVerifier().validateJWT(authHeader);
JsonObject responseJson = toJsonObj(response.readEntity(String.class));
String dbId = responseJson.getString(User.JSON_KEY_USER_ID);
user.setId(dbId);
// Find user in the database.
BasicDBObject dbUser =
(BasicDBObject) database.getCollection("users").findOne(new ObjectId(dbId));
assertTrue("User rFeynman was NOT found in database.", dbUser != null);
assertTrue("User rFeynman does not contain expected data.", user.isEqual(dbUser));
// Test 1: Login the user on non-ssl port. We should be redirected to
// the SSL port.
String postUrl = "http://" + libertyHostname + ":" + libertyPort + "/logins";
JsonObjectBuilder loginPayload = Json.createObjectBuilder();
loginPayload.add(User.JSON_KEY_USER_NAME, user.userName);
loginPayload.add(User.JSON_KEY_USER_PASSWORD, user.password);
response = processRequest(postUrl, "POST", loginPayload.build().toString(), authHeader);
assertEquals("HTTP response code should have been 302.", 302, response.getStatus());
}
示例7: addToCart
import javax.json.JsonObjectBuilder; //導入方法依賴的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());
}
示例8: 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();
}
示例9: 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();
}
示例10: addInput
import javax.json.JsonObjectBuilder; //導入方法依賴的package包/類
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;
}
示例11: 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;
}
示例12: 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();
}
示例13: createJsonBuilder
import javax.json.JsonObjectBuilder; //導入方法依賴的package包/類
/** Allow for a JsonObject to be modified */
public JsonObjectBuilder createJsonBuilder(JsonObject source) {
JsonObjectBuilder builder = Json.createObjectBuilder();
for (String key : source.keySet()) {
builder.add(key, source.get(key));
}
return builder;
}
示例14: 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();
}
示例15: getJsonObjectBuilderForResult
import javax.json.JsonObjectBuilder; //導入方法依賴的package包/類
public JsonObjectBuilder getJsonObjectBuilderForResult(String osName, String osVersion) {
JsonObjectBuilder jsonObjectBuilder =
Json.createObjectBuilder().add("browserName", this.getBrowserName());
// Select the version
String myVersion = null;
if (Utility.isNotNullAndNotEmpty(this.userAgentVersion))
myVersion = this.userAgentVersion;
else if (Utility.isNotNullAndNotEmpty(this.webDriverVersion))
myVersion = this.webDriverVersion;
else if (Utility.isNotNullAndNotEmpty(this.version))
myVersion = this.version;
if (myVersion != null)
jsonObjectBuilder.add("version", myVersion);
// Select the platform
String myPlatform = null;
if (Utility.isNotNullAndNotEmpty(this.userAgentPlatform)) {
myPlatform = this.userAgentPlatform;
} else if (Utility.isNotNullAndNotEmpty(this.webDriverPlatform)) {
myPlatform = this.webDriverPlatform;
if (myPlatform.equalsIgnoreCase("ANY") && Utility.isNotNullAndNotEmpty(this.platform))
myPlatform = this.platform;
} else if (Utility.isNotNullAndNotEmpty(this.platform)) {
myPlatform = this.platform;
}
if (osName != null && osVersion != null) {
if (!myPlatform.toLowerCase().contains("linux") && !myPlatform.matches("[0-9]")) {
if (myPlatform.toLowerCase().startsWith("win") && osName.toLowerCase().startsWith("win")
|| myPlatform.toLowerCase().startsWith("mac")
&& osName.toLowerCase().startsWith("mac")) {
myPlatform = osName + osVersion;
if (logger.isDebugEnabled())
logger.debug("replacing platform info from exception info - replacing: " + myPlatform
+ " with: " + osName + osVersion);
}
}
}
if (myPlatform != null)
jsonObjectBuilder.add("platform", myPlatform);
return jsonObjectBuilder;
}