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


Java JsonArrayBuilder.add方法代码示例

本文整理汇总了Java中javax.json.JsonArrayBuilder.add方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArrayBuilder.add方法的具体用法?Java JsonArrayBuilder.add怎么用?Java JsonArrayBuilder.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.json.JsonArrayBuilder的用法示例。


在下文中一共展示了JsonArrayBuilder.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onOpen

import javax.json.JsonArrayBuilder; //导入方法依赖的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: getJson

import javax.json.JsonArrayBuilder; //导入方法依赖的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();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:19,代码来源:Group.java

示例3: signUp

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
@Override
public User signUp() {
    final JsonArray registered = this.server.storage().build()
        .getJsonArray("users");
    final JsonArrayBuilder users = Json.createArrayBuilder();
    for(final JsonValue user: registered) {
        users.add(user);
    }
    users.add(
        Json.createObjectBuilder()
            .add(
                this.json.getString("username"),
                this.json
            )
    );
    this.server.storage().add("users", users.build());
    return new MkUser(this.server, this.json.getString("username"));
}
 
开发者ID:decorators-squad,项目名称:versioneye-api,代码行数:19,代码来源:MkNewUser.java

示例4: addTeams

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
/**
 * This method adds teams of the specified page to the teams array.
 *
 * @param arrBuilder specifies the array builder to add the teams into.
 * @param year specifies the optional year, null for all years.
 * @param pageNum specifies the page number.
 * @param verbosity specifies optional verbosity, null for full verbosity.
 * @param statusOut specifies standard output stream for command status, can be null for quiet mode.
 * @return true if successful, false if failed.
 */
private boolean addTeams(
    JsonArrayBuilder arrBuilder, String year, int pageNum, String verbosity, PrintStream statusOut)
{
    String request = "teams/";
    if (year != null) request += year + "/";
    request += pageNum;
    if (verbosity != null) request += "/" + verbosity;

    JsonStructure data = get(request, statusOut, header);
    boolean success;
    if (data != null && data.getValueType() == JsonValue.ValueType.ARRAY && !((JsonArray)data).isEmpty())
    {
        for (JsonValue team: (JsonArray)data)
        {
            arrBuilder.add(team);
        }
        success = true;
    }
    else
    {
        success = false;
    }

    return success;
}
 
开发者ID:trc492,项目名称:TBAShell,代码行数:36,代码来源:TbaApiV3.java

示例5: getJson

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
/**
 * Create a JSON string based on the content of this group
 *
 * @return The JSON string with the content of this group
 */
public String getJson() {
  JsonObjectBuilder group = Json.createObjectBuilder();
  if (id != null) {
    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();
}
 
开发者ID:OpenLiberty,项目名称:sample-acmegifts,代码行数:22,代码来源:Group.java

示例6: buildUserResponseObject

import javax.json.JsonArrayBuilder; //导入方法依赖的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

示例7: dumpStackTrace

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
@GET
@Produces("application/json")
public Response dumpStackTrace() {
    JsonArrayBuilder threadsArrayJson = Json.createArrayBuilder();
    for (ThreadInfo info : jmxInspector.getThreadInfo()) {
        JsonObjectBuilder threadJson = Json.createObjectBuilder();
        threadJson.add("threadName", info.getThreadName())
                .add("threadId", info.getThreadId())
                .add("blockedTime", info.getBlockedTime())
                .add("blockedCount", info.getBlockedCount())
                .add("waitedTime", info.getWaitedTime())
                .add("waitedCount", info.getWaitedCount())
                .add("lockName", nullSafe(info.getLockName()))
                .add("lockOwnerName", nullSafe(info.getLockOwnerName()))
                .add("inNative", info.isInNative())
                .add("suspended", info.isSuspended())
                .add("threadState", info.getThreadState().toString())
                .add("stackTrace", buildStackTrace(info.getStackTrace()))
                .add("lockedMonitors", buildLockedMonitors(info.getLockedMonitors()))
                .add("lockedSynchronizers", buildLockedSynchronizers(info.getLockedSynchronizers()))
                .add("lockInfo", buildLockInfo(info.getLockInfo()));
        threadsArrayJson.add(threadJson);
    }

    return Response.ok(threadsArrayJson.build()).build();
}
 
开发者ID:ivannov,项目名称:javaee-actuator,代码行数:27,代码来源:DumpResource.java

示例8: cpsiaToJSON

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
/**
 * Turn the CPSIA statements into a json array
 * @return json
 */
private JsonArrayBuilder cpsiaToJSON()
{
  final JsonArrayBuilder obj = Json.createArrayBuilder();

  int ct = 0;

  for ( CPSIA c : cpsiaStatements )
  {
    if ( c == null )
      continue;

    obj.add( c.getText());
    if ( ++ct == 7 )
      break;
  }

  return obj;
}
 
开发者ID:SixArmDonkey,项目名称:aerodrome-for-jet,代码行数:23,代码来源:ProductRec.java

示例9: getTimeZones

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
@GET
@ApiOperation(value = "Get timezones",
        response = String.class,
        responseContainer = "List")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "Successful retrieval of timezones. It can be an empty list."),
        @ApiResponse(code = 401, message = "Unauthorized"),
        @ApiResponse(code = 500, message = "Internal server error")
})
@Produces(MediaType.APPLICATION_JSON)
public Response getTimeZones() {
    JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
    for (String timeZone : TimeZone.getAvailableIDs()) {
        arrayBuilder.add(timeZone);
    }
    return Response.ok().entity(arrayBuilder.build()).build();
}
 
开发者ID:polarsys,项目名称:eplmp,代码行数:18,代码来源:TimeZoneResource.java

示例10: getLinks

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
@GET
@Path("{id}/links")
public Response getLinks(@PathParam("id") long idSupplied, @QueryParam("key") String apiKey) {
    try {
        AuthenticatedUser u = findUserOrDie(apiKey);
        if (!u.isSuperuser()) {
            return errorResponse(Response.Status.FORBIDDEN, "Not a superuser");
        }
        Dataset dataset = findDatasetOrDie(idSupplied);

        long datasetId = dataset.getId();
        List<Dataverse> dvsThatLinkToThisDatasetId = dataverseSvc.findDataversesThatLinkToThisDatasetId(datasetId);
        JsonArrayBuilder dataversesThatLinkToThisDatasetIdBuilder = Json.createArrayBuilder();
        for (Dataverse dataverse : dvsThatLinkToThisDatasetId) {
            dataversesThatLinkToThisDatasetIdBuilder.add(dataverse.getAlias() + " (id " + dataverse.getId() + ")");
        }
        JsonObjectBuilder response = Json.createObjectBuilder();
        response.add("dataverses that link to dataset id " + datasetId, dataversesThatLinkToThisDatasetIdBuilder);
        return okResponse(response);
    } catch (WrappedResponse wr) {
        return wr.getResponse();
    }
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:24,代码来源:Datasets.java

示例11: altImgToJSON

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
/**
 * Turn the alternate images into json
 * @return alt images
 */
private JsonArrayBuilder altImgToJSON()
{
  final JsonArrayBuilder obj = Json.createArrayBuilder();

  for ( ProductImageSlot key : alternateImages.keySet())
  {
    obj.add( Json.createObjectBuilder()
     .add( "image_slot_id", key.getSlot())
     .add( "image_url", alternateImages.get( key ))
     .build()
    );
  }

  return obj;
}
 
开发者ID:SixArmDonkey,项目名称:aerodrome-for-jet,代码行数:20,代码来源:ProductRec.java

示例12: list

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
@GET
public Response list(@QueryParam("key") String key) {
    String expectedKey = settingsSvc.get(API_KEY_IN_SETTINGS);
    if (expectedKey == null) {
        return errorResponse(Status.SERVICE_UNAVAILABLE, "Dataverse config issue: No API key defined for built in user management");
    }
    if (!expectedKey.equals(key)) {
        return badApiKey(key);
    }
    JsonArrayBuilder bld = Json.createArrayBuilder();

    for (BuiltinUser u : builtinUserSvc.findAll()) {
        bld.add(json(u));
    }

    return okResponse(bld);
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:18,代码来源:BuiltinUsers.java

示例13: getContentInDatabaseButStaleInOrMissingFromSolr

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
private JsonObjectBuilder getContentInDatabaseButStaleInOrMissingFromSolr() {
    List<Dataverse> stateOrMissingDataverses = indexService.findStaleOrMissingDataverses();
    List<Dataset> staleOrMissingDatasets = indexService.findStaleOrMissingDatasets();
    JsonArrayBuilder jsonStateOrMissingDataverses = Json.createArrayBuilder();
    for (Dataverse dataverse : stateOrMissingDataverses) {
        jsonStateOrMissingDataverses.add(dataverse.getId());
    }
    JsonArrayBuilder datasetsInDatabaseButNotSolr = Json.createArrayBuilder();
    for (Dataset dataset : staleOrMissingDatasets) {
        datasetsInDatabaseButNotSolr.add(dataset.getId());
    }
    JsonObjectBuilder contentInDatabaseButStaleInOrMissingFromSolr = Json.createObjectBuilder()
            /**
             * @todo What about files? Currently files are always indexed
             * along with their parent dataset
             */
            .add("dataverses", jsonStateOrMissingDataverses.build().size())
            .add("datasets", datasetsInDatabaseButNotSolr.build().size());
    return contentInDatabaseButStaleInOrMissingFromSolr;
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:21,代码来源:Index.java

示例14: createDataverse

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
private static Response createDataverse(TestDataverse dataverseToCreate, TestUser creator) {
    JsonArrayBuilder contactArrayBuilder = Json.createArrayBuilder();
    contactArrayBuilder.add(Json.createObjectBuilder().add("contactEmail", creator.getEmail()));
    JsonArrayBuilder subjectArrayBuilder = Json.createArrayBuilder();
    subjectArrayBuilder.add("Other");
    JsonObject dvData = Json.createObjectBuilder()
            .add("alias", dataverseToCreate.alias)
            .add("name", dataverseToCreate.name)
            .add("dataverseContacts", contactArrayBuilder)
            .add("dataverseSubjects", subjectArrayBuilder)
            .build();
    Response createDataverseResponse = given()
            .body(dvData.toString()).contentType(ContentType.JSON)
            .when().post("/api/dataverses/:root?key=" + creator.apiToken);
    return createDataverseResponse;
}
 
开发者ID:pengchengluo,项目名称:Peking-University-Open-Research-Data-Platform,代码行数:17,代码来源:SearchIT.java

示例15: authenticate

import javax.json.JsonArrayBuilder; //导入方法依赖的package包/类
/**
 * Add authenticated user to the MkServer.
 * @param authenticated The user to authenticate.
 */
private void authenticate(final Authenticated authenticated) {
    final JsonArray online = this.server.storage().build()
        .getJsonArray("authenticated");
    final JsonArrayBuilder users = Json.createArrayBuilder();
    for(final JsonValue user: online) {
        users.add(user);
    }
    users.add(Json.createObjectBuilder().add(
        this.username, authenticated.json())
    );
    this.server.storage().add("authenticated", users.build());
}
 
开发者ID:decorators-squad,项目名称:versioneye-api,代码行数:17,代码来源:MkVersionEye.java


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