本文整理汇总了Java中javax.json.Json.createArrayBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java Json.createArrayBuilder方法的具体用法?Java Json.createArrayBuilder怎么用?Java Json.createArrayBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.json.Json
的用法示例。
在下文中一共展示了Json.createArrayBuilder方法的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);
}
}
示例2: readMessages
import javax.json.Json; //导入方法依赖的package包/类
private JsonArray readMessages(JsonReader reader) throws Exception {
JsonArrayBuilder b = Json.createArrayBuilder();
JsonObject obj;
try{
obj = reader.readObject();
} finally {
reader.close();
}
obj.entrySet().forEach(e ->
{
Message msg=new Message();
JsonObject m;
m = msg.generate(e.getValue().toString(), "@id", "http://inbox.rerum.io/id/" + e.getKey() + "");
if(MOTIVATION.length()==0 || MOTIVATION.contains(m.getJsonString("motivation").toString())){
b.add(m);
}
});
JsonArray messages = b.build();
return messages;
}
示例3: getJson
import javax.json.Json; //导入方法依赖的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: 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();
}
示例5: 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();
}
示例6: authenticate
import javax.json.Json; //导入方法依赖的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());
}
示例7: toJson
import javax.json.Json; //导入方法依赖的package包/类
@Override
public JsonStructure toJson() {
JsonArrayBuilder result = Json.createArrayBuilder();
iterate().stream()
.map(Category::toJson)
.forEach(result::add);
return result.build();
}
示例8: getSupportedOpenShiftClusters
import javax.json.Json; //导入方法依赖的package包/类
@GET
@Path("/clusters")
@Produces(MediaType.APPLICATION_JSON)
public JsonArray getSupportedOpenShiftClusters(@HeaderParam(HttpHeaders.AUTHORIZATION) final String authorization,
@Context HttpServletRequest request) {
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
Set<OpenShiftCluster> clusters = clusterRegistry.getClusters();
if (request.getParameterMap().containsKey("all") || openShiftServiceFactory.getDefaultIdentity().isPresent()) {
// Return all clusters
clusters
.stream()
.map(OpenShiftCluster::getId)
.forEach(arrayBuilder::add);
} else {
final KeycloakService keycloakService = this.keycloakServiceInstance.get();
clusters.parallelStream().map(OpenShiftCluster::getId)
.forEach(clusterId ->
keycloakService.getIdentity(clusterId, authorization)
.ifPresent(token -> arrayBuilder.add(clusterId)));
}
return arrayBuilder.build();
}
示例9: buildLspNotification
import javax.json.Json; //导入方法依赖的package包/类
private String buildLspNotification(int type, List<String> artifacts) {
JsonArrayBuilder changes = Json.createArrayBuilder();
for (String sUrl : artifacts) {
changes.add(Json.createObjectBuilder().add("uri", "file://" + sUrl).add("type", type).build());
}
JsonObject bodyObj = Json.createObjectBuilder()
.add("jsonrpc", "2.0")
.add("method", "workspace/didChangeWatchedFiles")
.add("params", Json.createObjectBuilder()
.add("changes", changes.build())
.build())
.build();
String body = bodyObj.toString();
return String.format("Content-Length: %d\r\n\r\n%s", body.length(), body);
}
示例10: print
import javax.json.Json; //导入方法依赖的package包/类
@Override
public void print(String name, Collection<Response> collection) {
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
collection.forEach(response -> {
JsonMedia entry = new JsonMedia();
response.printOn(entry);
arrayBuilder.add(entry.getContent());
});
this.json.add(name, arrayBuilder.build());
}
示例11: getTeams
import javax.json.Json; //导入方法依赖的package包/类
/**
* This method sends a Team List Request.
*
* @param year specifies the optional year, null for all years.
* @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 team list data.
*/
public JsonStructure getTeams(String year, String verbosity, PrintStream statusOut)
{
JsonArrayBuilder arrBuilder = Json.createArrayBuilder();
for (int page = 0; ; page++)
{
if (!addTeams(arrBuilder, year, page, verbosity, statusOut))
break;
}
return arrBuilder.build();
}
示例12: withNumberArray
import javax.json.Json; //导入方法依赖的package包/类
T withNumberArray(String name, List<Long> numList) {
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
for (long l : numList) {
arrayBuilder.add(l);
}
return create(toObjectBuilder().add(name, arrayBuilder));
}
示例13: withStringArray
import javax.json.Json; //导入方法依赖的package包/类
T withStringArray(String name, List<String> stringList) {
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
for (String s : stringList) {
arrayBuilder.add(s);
}
return create(toObjectBuilder().add(name, arrayBuilder));
}
示例14: withObjectArray
import javax.json.Json; //导入方法依赖的package包/类
T withObjectArray(String name, List<? extends DevtoolsObject> objectList) {
JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
for (DevtoolsObject t : objectList) {
arrayBuilder.add(t.object);
}
return create(toObjectBuilder().add(name, arrayBuilder));
}
示例15: toJson
import javax.json.Json; //导入方法依赖的package包/类
/**
* Creates JSON representation of given collection.
*
* @return JSON structure.
*/
@Override
public JsonStructure toJson() {
JsonArrayBuilder result = Json.createArrayBuilder();
col.stream()
.map(JsonSource::toJson)
.forEach(result::add);
return result.build();
}