Example usage for javax.json JsonArrayBuilder build

List of usage examples for javax.json JsonArrayBuilder build

Introduction

In this page you can find the example usage for javax.json JsonArrayBuilder build.

Prototype

JsonArray build();

Source Link

Document

Returns the current array.

Usage

From source file:co.runrightfast.core.utils.JsonUtils.java

static javax.json.JsonArray toJsonArray(final List<String> stringList) {
    if (CollectionUtils.isEmpty(stringList)) {
        return EMPTY_ARRAY;
    }/* ww w.  j a  va  2 s . com*/

    final JsonArrayBuilder json = Json.createArrayBuilder();
    stringList.forEach(json::add);
    return json.build();
}

From source file:co.runrightfast.core.utils.JsonUtils.java

static JsonArray toJsonArray(final String[] stringList) {
    if (ArrayUtils.isEmpty(stringList)) {
        return EMPTY_ARRAY;
    }/*from  w  w w  .j a  v  a  2 s.  co  m*/

    final JsonArrayBuilder builder = Json.createArrayBuilder();
    for (int i = 0; i < stringList.length; i++) {
        builder.add(stringList[i]);
    }
    return builder.build();
}

From source file:co.runrightfast.vertx.core.protobuf.MessageConversions.java

static JsonArray toJsonArray(final Collection<RunRightFastVerticleDeployment> deployments) {
    if (deployments == null) {
        return JsonUtils.EMPTY_ARRAY;
    }// w ww .j av  a 2  s .  co  m

    final JsonArrayBuilder jsonArray = Json.createArrayBuilder();
    deployments.stream().forEach(deployment -> jsonArray.add(deployment.toJson()));
    return jsonArray.build();
}

From source file:com.buffalokiwi.aerodrome.jet.Utils.java

public static <T extends Jsonable> JsonArray jsonableToArray(List<T> data) {
    final JsonArrayBuilder ab = Json.createArrayBuilder();

    if (data != null) {
        for (T t : data) {
            ab.add(t.toJSON());// w ww . ja  v  a 2 s . c o  m
        }
    }

    return ab.build();
}

From source file:org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration.java

/**
 * Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in YAML format
 *
 * @param configStream A stream opened on a YAML document containing network configuration details
 * @return A new ChaincodeCollectionConfiguration instance
 * @throws InvalidArgumentException/*from  w  w  w.  j a  v a  2s  .  c o m*/
 */
public static ChaincodeCollectionConfiguration fromYamlStream(InputStream configStream)
        throws InvalidArgumentException, ChaincodeCollectionConfigurationException {

    logger.trace("ChaincodeCollectionConfiguration.fromYamlStream...");

    // Sanity check
    if (configStream == null) {
        throw new InvalidArgumentException("ConfigStream must be specified");
    }

    Yaml yaml = new Yaml();

    @SuppressWarnings("unchecked")
    List<Object> map = yaml.load(configStream);

    JsonArrayBuilder builder = Json.createArrayBuilder(map);

    JsonArray jsonConfig = builder.build();
    return fromJsonObject(jsonConfig);
}

From source file:org.dcm4che3.tool.qc.QC.java

private static JsonArray initPatientObject(QC qc) {
    JsonArrayBuilder builder = Json.createArrayBuilder()
            .add(toAttributesObject(qc.getSourcePatientAttributes()))
            .add(toAttributesObject(qc.getTargetPatientAttributes()));
    return builder.build();
}

From source file:onl.area51.httpd.rest.JsonEntity.java

public JsonEntity(JsonArrayBuilder b) {
    this(b.build());
}

From source file:nl.sidn.dnslib.message.records.dnssec.NSEC3ResourceRecord.java

@Override
public JsonObject toJSon() {
    JsonObjectBuilder builder = super.createJsonBuilder();
    builder.add("rdata",
            Json.createObjectBuilder().add("hash-algorithm", hashAlgorithm.name()).add("flags", flags)
                    .add("iterations", (int) iterations).add("salt-length", saltLength)
                    .add("salt", Hex.encodeHexString(salt)).add("hash-length", (int) hashLength)
                    .add("nxt-own-name", nexthashedownername));

    JsonArrayBuilder typeBuilder = Json.createArrayBuilder();
    for (TypeMap type : types) {
        typeBuilder.add(type.getType().name());
    }/*  w w w .  jav a2 s. co m*/
    return builder.add("types", typeBuilder.build()).build();
}

From source file:org.grogshop.services.endpoints.impl.ShopUserProfileServiceImpl.java

@Override
public Response getInterests(@NotNull @PathParam("user_id") Long user_id) throws ServiceException {
    List<Interest> interests = profileService.getInterests(user_id);
    log.info("Interests from the database: (" + user_id + ") " + interests);

    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    for (Interest i : interests) {
        jsonArrayBuilder//from w  ww  .  j  a v a  2 s.  c  o m
                .add(Json.createObjectBuilder().add("name", i.getName()).add("imagePath", i.getImageURL()));
    }
    JsonArray build = jsonArrayBuilder.build();
    return Response.ok(build.toString()).build();
}

From source file:com.buffalokiwi.aerodrome.jet.Utils.java

/**
 * Turn some list of Jsonable into a json array 
 * @param <T>/*from   www. j a  v  a  2s  .  co  m*/
 * @param data list
 * @return json array 
 */
public static <T extends Object> JsonArray toJsonArray(List<T> data) {
    final JsonArrayBuilder out = Json.createArrayBuilder();

    for (final Object obj : data) {
        if (obj == null)
            out.addNull();
        else if (obj instanceof Jsonable)
            out.add(((Jsonable) obj).toJSON());
        else if (obj instanceof JsonValue)
            out.add((JsonValue) obj);
        else if (obj instanceof BigDecimal)
            out.add((BigDecimal) obj);
        else if (obj instanceof BigInteger)
            out.add((BigInteger) obj);
        else if (obj instanceof Integer)
            out.add((Integer) obj);
        else if (obj instanceof Long)
            out.add((Long) obj);
        else if (obj instanceof Double)
            out.add((Double) obj);
        else if (obj instanceof Boolean)
            out.add((Boolean) obj);
        else if (obj instanceof JsonObjectBuilder)
            out.add((JsonObjectBuilder) obj);
        else if (obj instanceof JsonArrayBuilder)
            out.add((JsonArrayBuilder) obj);
        else
            out.add(obj.toString());
    }

    return out.build();
}