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


Java Json.createObjectBuilder方法代码示例

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

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

示例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();
}
 
开发者ID:samolisov,项目名称:bluemix-liberty-microprofile-demo,代码行数:19,代码来源:ReservationJsonAdapter.java

示例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;
    }
 
开发者ID:h2mch,项目名称:poi,代码行数:24,代码来源:ExampleStore.java

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

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

示例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();
}
 
开发者ID:AdamBien,项目名称:javaee-calculator,代码行数:10,代码来源:MetricsCounter.java

示例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();
}
 
开发者ID:decorators-squad,项目名称:versioneye-api,代码行数:9,代码来源:MkStorage.java

示例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();
}
 
开发者ID:h2mch,项目名称:poi,代码行数:9,代码来源:ConfigurationResource.java

示例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;
}
 
开发者ID:google,项目名称:devtools-driver,代码行数:9,代码来源:JavaxJson.java

示例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());
}
 
开发者ID:clytras,项目名称:AccessConverter,代码行数:29,代码来源:AccessConverter.java

示例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();
}
 
开发者ID:openknowledge,项目名称:java-ee-simple-sample,代码行数:13,代码来源:ValidationExceptionMapper.java

示例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());
}
 
开发者ID:PacktPublishing,项目名称:Architecting-Modern-Java-EE-Applications,代码行数:12,代码来源:BookClient.java

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

示例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());

}
 
开发者ID:dainesch,项目名称:HueSense,代码行数:11,代码来源:HueComm.java


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