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


Java Json.createBuilderFactory方法代码示例

本文整理汇总了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();
  }
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:19,代码来源:OccasionResource.java

示例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;
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:23,代码来源:NotificationRetryBean.java

示例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");
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:81,代码来源:OccasionResourceTest.java


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