本文整理汇总了Java中javax.json.Json.createBuilderFactory方法的典型用法代码示例。如果您正苦于以下问题:Java Json.createBuilderFactory方法的具体用法?Java Json.createBuilderFactory怎么用?Java Json.createBuilderFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.Json
的用法示例。
在下文中一共展示了Json.createBuilderFactory方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildPostRunResponse
import javax.json.Json; //导入方法依赖的package包/类
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();
}
示例2: makeNotificationConnection
import javax.json.Json; //导入方法依赖的package包/类
@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;
}
示例3: testOccasionsForGroup
import javax.json.Json; //导入方法依赖的package包/类
/** Test the ability to retrieve a list of occasions for a given group */
@Test
public void testOccasionsForGroup() {
logger.entering(
clazz, name.getMethodName(), "\n\n+ + + + + Entering " + name.getMethodName() + "\n\n");
String groupId = "3333";
/*
* build the json payload for the occasions
*/
JsonBuilderFactory factory = Json.createBuilderFactory(null);
// collect the expected output in this
JsonArrayBuilder resultsBuilder = factory.createArrayBuilder();
// build the json payload for occasion 1
List<Occasion.Contribution> contributions = new ArrayList<>();
contributions.add(new Occasion.Contribution("0001", 20));
Occasion occasion =
new Occasion(
/* ID */ null,
/* date */ "2117-07-31",
/* group ID */ "1111", // different ID than the others in this test so it's omitted
// from the results
/* interval */ "annual",
/* occasion name */ "John Doe's Birthday",
/* organizer ID */ "0001",
/* recipient ID */ "9998",
contributions);
// insert the occasion into the db
collection.insert(occasion.toDbo());
// occasion1 belongs to a different group. omitted from expected results
// build the json payload for occasion 2
contributions = new ArrayList<>();
contributions.add(new Occasion.Contribution("0002", 50));
contributions.add(new Occasion.Contribution("0003", 50));
occasion =
new Occasion(
/* ID */ null,
/* date */ "2117-09-30",
/* group ID */ groupId,
/* interval */ "annual",
/* occasion name */ "Jill Doe's Birthday",
/* organizer ID */ "0002",
/* recipient ID */ "9997",
contributions);
// insert the occasion into the db and add the result to the expected result array
collection.insert(occasion.toDbo());
occasion = new Occasion(collection.findOne(occasion.toDbo()));
resultsBuilder.add(occasion.toJson());
// build the json payload for occasion 3
contributions = new ArrayList<>();
contributions.add(new Occasion.Contribution("9999", 20));
contributions.add(new Occasion.Contribution("8888", 50));
occasion =
new Occasion(
/* ID */ null,
/* date */ "2018-01-31",
/* group ID */ groupId,
/* interval */ "annual",
/* occasion name */ "Jason Doe's Birthday",
/* organizer ID */ "9999",
/* recipient ID */ "9996",
contributions);
// insert the occasion into the db and add the result to the expected result array
collection.insert(occasion.toDbo());
occasion = new Occasion(collection.findOne(occasion.toDbo()));
resultsBuilder.add(occasion.toJson());
testEndpoint("/?groupId=" + groupId, "GET", resultsBuilder.build().toString(), 200);
logger.exiting(
clazz, name.getMethodName(), "\n\n- - - - - Exiting " + name.getMethodName() + "\n\n");
}