本文整理了Java中javax.json.Json.createArrayBuilder()
方法的一些代码示例,展示了Json.createArrayBuilder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.createArrayBuilder()
方法的具体详情如下:
包路径:javax.json.Json
类名称:Json
方法名:createArrayBuilder
[英]Creates a JSON array builder
[中]创建JSON数组生成器
代码示例来源:origin: stanfordnlp/CoreNLP
private static JsonArrayBuilder jsonArrayBuilderFromMapCounter(Map<String, List<Integer>> mapCounter) {
JsonArrayBuilder arrobj = Json.createArrayBuilder();
for (Entry<String, List<Integer>> sen : mapCounter.entrySet()) {
JsonObjectBuilder obj = Json.createObjectBuilder();
JsonArrayBuilder tokens = Json.createArrayBuilder();
for(Integer i : sen.getValue()){
tokens.add(i);
}
obj.add(sen.getKey(),tokens);
arrobj.add(obj);
}
return arrobj;
}
代码示例来源:origin: wildfly/wildfly
@Override
public JsonArray add(JsonValue value) {
//TODO should we check for arrayoutofbounds?
// The spec seems to say index = array.size() is allowed. This is handled as append
JsonArrayBuilder builder = Json.createArrayBuilder(this.array);
if (index == -1 || index == array.size()) {
builder.add(value);
} else {
if(index < array.size()) {
builder.add(index, value);
} else {
throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size()));
}
}
return builder.build();
}
代码示例来源:origin: jeremylong/DependencyCheck
payloadBuilder.add("name", packageJson.getString("name"));
payloadBuilder.add("version", packageJson.getString("version"));
final JsonObject module = dependencies.getJsonObject(moduleName);
final String version = module.getString("version");
requiresBuilder.add(moduleName, version);
payloadBuilder.add("requires", requiresBuilder.build());
payloadBuilder.add("dependencies", packageJson.getJsonObject("dependencies"));
payloadBuilder.add("install", Json.createArrayBuilder().build());
payloadBuilder.add("remove", Json.createArrayBuilder().build());
payloadBuilder.add("metadata", Json.createObjectBuilder()
.add("npm_version", "6.1.0")
代码示例来源:origin: stanfordnlp/CoreNLP
public String getAllAnnotations(String input) {
JsonObjectBuilder objsent = Json.createObjectBuilder();
int tokenid = 0;
for(CoreLabel l : Data.sents.get(input).getTokens()){
boolean haslabel = false;
JsonArrayBuilder labelArr = Json.createArrayBuilder();
for(Map.Entry<String, Class<? extends TypesafeMap.Key<String>>> en: this.humanLabelClasses.entrySet()){
if(!l.get(en.getValue()).equals(backgroundSymbol)){
haslabel = true;
labelArr.add(en.getKey());
}
}
if(haslabel)
objsent.add(String.valueOf(tokenid), labelArr);
tokenid++;
}
return objsent.build().toString();
}
代码示例来源:origin: wildfly/wildfly
private boolean hasValidAudience(JsonObject claims) throws RealmUnavailableException {
if (this.audiences.isEmpty()) return true;
JsonValue audience = claims.get("aud");
if (audience == null) {
log.debug("Token does not contain an audience claim");
return false;
}
JsonArray audClaimArray;
if (JsonValue.ValueType.STRING.equals(audience.getValueType())) {
audClaimArray = Json.createArrayBuilder().add(audience).build();
} else {
audClaimArray = (JsonArray) audience;
}
boolean valid = audClaimArray.stream()
.map(jsonValue -> (JsonString) jsonValue)
.anyMatch(audience1 -> audiences.contains(audience1.getString()));
if (!valid) {
log.debugf("Audience check failed. Provided [%s] but was expected [%s].", audClaimArray.toArray(), this.audiences);
}
return valid;
}
代码示例来源:origin: org.jboss.forge/forge-service-core
public void describeResult(JsonObjectBuilder builder, Result result)
{
JsonArrayBuilder array = createArrayBuilder();
collectResults(array, result);
builder.add("results", array);
}
代码示例来源:origin: stanfordnlp/CoreNLP
public String getSetWordsAsJson(Map<String, Counter<CandidatePhrase>> words){
JsonObjectBuilder obj = Json.createObjectBuilder();
for(String label: getLabels()){
JsonArrayBuilder arr = Json.createArrayBuilder();
for(CandidatePhrase k: words.get(label).keySet())
arr.add(k.getPhrase());
obj.add(label, arr);
}
return obj.build().toString();
}
代码示例来源:origin: org.glassfish/javax.json
@Override
public JsonArray add(JsonValue value) {
//TODO should we check for arrayoutofbounds?
// The spec seems to say index = array.size() is allowed. This is handled as append
JsonArrayBuilder builder = Json.createArrayBuilder(this.array);
if (index == -1 || index == array.size()) {
builder.add(value);
} else {
if(index < array.size()) {
builder.add(index, value);
} else {
throw new JsonException(JsonMessages.NODEREF_ARRAY_INDEX_ERR(index, array.size()));
}
}
return builder.build();
}
代码示例来源:origin: sdaschner/jaxrs-analyzer
private void renderTags() {
if (options.isRenderTags()) {
final JsonArrayBuilder tags = Json.createArrayBuilder();
resources.getResources().stream()
.map(this::extractTag).filter(Objects::nonNull)
.distinct().sorted()
.map(tag -> Json.createObjectBuilder().add("name", tag))
.forEach(tags::add);
builder.add("tags", tags);
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public String getAllAnnotations() {
JsonObjectBuilder obj = Json.createObjectBuilder();
for(Map.Entry<String, DataInstance> sent: Data.sents.entrySet()){
boolean sentHasLabel = false;
JsonObjectBuilder objsent = Json.createObjectBuilder();
int tokenid = 0;
for(CoreLabel l : sent.getValue().getTokens()){
boolean haslabel = false;
JsonArrayBuilder labelArr = Json.createArrayBuilder();
for(Map.Entry<String, Class<? extends TypesafeMap.Key<String>>> en: this.humanLabelClasses.entrySet()){
if(!l.get(en.getValue()).equals(backgroundSymbol)){
haslabel = true;
sentHasLabel = true;
labelArr.add(en.getKey());
}
}
if(haslabel)
objsent.add(String.valueOf(tokenid), labelArr);
tokenid++;
}
if(sentHasLabel)
obj.add(sent.getKey(), objsent);
}
return obj.build().toString();
}
代码示例来源:origin: IQSS/dataverse
public static JsonArrayBuilder asJsonArray(Collection<String> strings) {
JsonArrayBuilder arr = Json.createArrayBuilder();
for (String s : strings) {
arr.add(s);
}
return arr;
}
代码示例来源:origin: IQSS/dataverse
private JsonObjectBuilder getNoResultsJSON(){
return Json.createObjectBuilder()
.add("userCount", 0)
.add("selectedPage", 1)
.add("bundleStrings", AuthenticatedUser.getBundleStrings())
.add("users", Json.createArrayBuilder()); // empty array
}
代码示例来源:origin: stanfordnlp/CoreNLP
public String getLearnedWordsAsJson(){
JsonObjectBuilder obj = Json.createObjectBuilder();
for(String label: getLabels()){
Counter<CandidatePhrase> learnedWords = getLearnedWords(label);
JsonArrayBuilder arr = Json.createArrayBuilder();
for(CandidatePhrase k: learnedWords.keySet())
arr.add(k.getPhrase());
obj.add(label, arr);
}
return obj.build().toString();
}
代码示例来源:origin: IQSS/dataverse
/**
* "publication_statuses" : [ name 1, name 2, etc.]
*
* @return
*/
public JsonArrayBuilder getListofSelectedPublicationStatuses(){
JsonArrayBuilder jsonArray = Json.createArrayBuilder();
for (String pubStatus : this.publicationStatuses){
jsonArray.add(pubStatus);
}
return jsonArray;
}
代码示例来源:origin: IQSS/dataverse
@Override
public void startField(DatasetField f) {
objectStack.push(jsonObjectBuilder());
// Invariant: all values are multiple. Diffrentiation between multiple and single is done at endField.
valueArrStack.push(Json.createArrayBuilder());
DatasetFieldType typ = f.getDatasetFieldType();
objectStack.peek().add("typeName", typ.getName());
objectStack.peek().add("multiple", typ.isAllowMultiples());
objectStack.peek().add("typeClass", typeClassString(typ));
}
代码示例来源:origin: stanfordnlp/CoreNLP
public String getLearnedWordsAsJsonLastIteration(){
JsonObjectBuilder obj = Json.createObjectBuilder();
for(String label: getLabels()){
Counter<CandidatePhrase> learnedWords = getLearnedWordsEachIter(label).lastEntry().getValue();
JsonArrayBuilder arr = Json.createArrayBuilder();
for(CandidatePhrase k: learnedWords.keySet())
arr.add(k.getPhrase());
obj.add(label, arr);
}
return obj.build().toString();
}
代码示例来源:origin: IQSS/dataverse
public static JsonArrayBuilder rolesToJson(List<DataverseRole> role) {
JsonArrayBuilder bld = Json.createArrayBuilder();
for (DataverseRole r : role) {
bld.add(JsonPrinter.json(r));
}
return bld;
}
代码示例来源:origin: stanfordnlp/CoreNLP
@Override
public void process(int id, Document document) {
JsonArrayBuilder clusters = Json.createArrayBuilder();
for (CorefCluster gold : document.goldCorefClusters.values()) {
JsonArrayBuilder c = Json.createArrayBuilder();
for (Mention m : gold.corefMentions) {
c.add(m.mentionID);
clusters.add(c.build());
goldClusterWriter.println(Json.createObjectBuilder().add(String.valueOf(id),
clusters.build()).build());
JsonArrayBuilder sentences = Json.createArrayBuilder();
for (CoreMap sentence : document.annotation.get(SentencesAnnotation.class)) {
sentences.add(getSentenceArray(sentence.get(CoreAnnotations.TokensAnnotation.class)));
JsonArrayBuilder featureNames = Json.createArrayBuilder()
.add("same-speaker")
.add("antecedent-is-mention-speaker")
String key = m1.mentionNum + " " + m2.mentionNum;
JsonArrayBuilder builder = Json.createArrayBuilder();
for (int val : CategoricalFeatureExtractor.pairwiseFeatures(
document, m1, m2, dictionaries, conll)) {
代码示例来源:origin: IQSS/dataverse
public JsonArrayBuilder getPublicationStatusesAsJSON() {
JsonArrayBuilder statuses = Json.createArrayBuilder();
for (String status : this.getPublicationStatuses()) {
statuses.add(status);
}
return statuses;
}
代码示例来源:origin: stanfordnlp/CoreNLP
JsonArrayBuilder obj = Json.createArrayBuilder();
for (Pair<Integer, Integer> sen2 : sen.getValue()) {
JsonArrayBuilder startend = Json.createArrayBuilder();
startend.add(sen2.first());
startend.add(sen2.second());
obj.add(startend);
senttokens.add(sen.getKey(), obj);
pats.add(en.getKey().toStringSimple(), senttokens);
JsonArrayBuilder sent = Json.createArrayBuilder();
for (CoreLabel l : sents.get(sentId).getTokens()) {
sent.add(l.word());
senttokens.add(sentId, sent);
内容来源于网络,如有侵权,请联系作者删除!