Example usage for javax.json JsonArrayBuilder add

List of usage examples for javax.json JsonArrayBuilder add

Introduction

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

Prototype

JsonArrayBuilder add(JsonArrayBuilder builder);

Source Link

Document

Adds a JsonArray from an array builder to the array.

Usage

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

@Override
public Response getAllItems() throws ServiceException {
    List<Item> allItems = itemsService.getAllItems();
    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    for (Item i : allItems) {
        jsonObjectBuilder.add("id", (i.getId() == null) ? "" : i.getId().toString())
                .add("user_id", (i.getUser().getId() == null) ? "" : i.getUser().getId().toString())
                .add("user_email", (i.getUser().getEmail() == null) ? "" : i.getUser().getEmail())
                .add("club_id", (i.getClub().getId() == null) ? "" : i.getClub().getId().toString())
                .add("type", (i.getType() == null) ? "" : i.getType().toString())
                .add("name", (i.getName() == null) ? "" : i.getName())
                .add("description", (i.getDescription() == null) ? "" : i.getDescription())
                .add("hasImage", i.hasImage())
                .add("minPrice", (i.getMinPrice() == null) ? "" : i.getMinPrice().toString())
                .add("maxPrice", (i.getMaxPrice() == null) ? "" : i.getMaxPrice().toString());

        if (i.getTags() != null) {
            JsonArrayBuilder jsonArrayBuilderInterest = Json.createArrayBuilder();
            for (String s : i.getTags()) {
                jsonArrayBuilderInterest.add(Json.createObjectBuilder().add("text", s));
            }//w  ww . j  a  va2  s.  com
            jsonObjectBuilder.add("tags", jsonArrayBuilderInterest);
        }
        jsonArrayBuilder.add(jsonObjectBuilder);
    }
    JsonArray jsonArray = jsonArrayBuilder.build();
    return Response.ok(jsonArray.toString()).build();

}

From source file:edu.harvard.iq.dataverse.mydata.MyDataFilterParams.java

public JsonObjectBuilder getDvObjectTypesAsJSON() {

    JsonArrayBuilder jsonArray = Json.createArrayBuilder();

    jsonArray
            .add(Json.createObjectBuilder().add("value", DvObject.DATAVERSE_DTYPE_STRING)
                    .add("label", SearchConstants.UI_DATAVERSES).add("selected", this.areDataversesIncluded()))
            .add(Json.createObjectBuilder().add("value", DvObject.DATASET_DTYPE_STRING)
                    .add("label", SearchConstants.UI_DATASETS).add("selected", this.areDatasetsIncluded()))
            .add(Json.createObjectBuilder().add("value", DvObject.DATAFILE_DTYPE_STRING)
                    .add("label", SearchConstants.UI_FILES).add("selected", this.areFilesIncluded()));

    JsonObjectBuilder jsonData = Json.createObjectBuilder();
    jsonData.add(SearchFields.TYPE, jsonArray);

    return jsonData;
}

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

@Override
public Response getAllItemsByClub(@PathParam("id") Long club_id) throws ServiceException {
    List<Item> allItems = itemsService.getAllItemsByClub(club_id);
    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    for (Item i : allItems) {
        jsonObjectBuilder.add("id", (i.getId() == null) ? "" : i.getId().toString())
                .add("user_id", (i.getUser().getId() == null) ? "" : i.getUser().getId().toString())
                .add("user_email", (i.getUser().getEmail() == null) ? "" : i.getUser().getEmail())
                .add("club_id", (i.getClub().getId() == null) ? "" : i.getClub().getId().toString())
                .add("type", (i.getType() == null) ? "" : i.getType().toString())
                .add("name", (i.getName() == null) ? "" : i.getName())
                .add("description", (i.getDescription() == null) ? "" : i.getDescription())
                .add("hasImage", i.hasImage())
                .add("minPrice", (i.getMinPrice() == null) ? "" : i.getMinPrice().toString())
                .add("maxPrice", (i.getMaxPrice() == null) ? "" : i.getMaxPrice().toString());

        if (i.getTags() != null) {
            JsonArrayBuilder jsonArrayBuilderInterest = Json.createArrayBuilder();
            for (String s : i.getTags()) {
                jsonArrayBuilderInterest.add(Json.createObjectBuilder().add("text", s));
            }/* w ww.  j  a v a 2s  .  c  o m*/
            jsonObjectBuilder.add("tags", jsonArrayBuilderInterest);

        }
        jsonArrayBuilder.add(jsonObjectBuilder);
    }
    JsonArray jsonArray = jsonArrayBuilder.build();
    return Response.ok(jsonArray.toString()).build();

}

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

@Override
public Response getAllItemsByUser(@PathParam("id") Long userId) throws ServiceException {
    List<Item> allItems = itemsService.getAllItemsByUser(userId);
    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    for (Item i : allItems) {
        jsonObjectBuilder.add("id", (i.getId() == null) ? "" : i.getId().toString())
                .add("user_id", (i.getUser().getId() == null) ? "" : i.getUser().getId().toString())
                .add("user_email", (i.getUser().getEmail() == null) ? "" : i.getUser().getEmail())
                .add("club_id", (i.getClub().getId() == null) ? "" : i.getClub().getId().toString())
                .add("type", (i.getType() == null) ? "" : i.getType().toString())
                .add("name", (i.getName() == null) ? "" : i.getName())
                .add("description", (i.getDescription() == null) ? "" : i.getDescription())
                .add("hasImage", i.hasImage())
                .add("minPrice", (i.getMinPrice() == null) ? "" : i.getMinPrice().toString())
                .add("maxPrice", (i.getMaxPrice() == null) ? "" : i.getMaxPrice().toString());

        if (i.getTags() != null) {
            JsonArrayBuilder jsonArrayBuilderInterest = Json.createArrayBuilder();
            for (String s : i.getTags()) {
                jsonArrayBuilderInterest.add(Json.createObjectBuilder().add("text", s));
            }//from ww  w .  j a  v  a2 s.  com
            jsonObjectBuilder.add("tags", jsonArrayBuilderInterest);

        }
        jsonArrayBuilder.add(jsonObjectBuilder);
    }
    JsonArray jsonArray = jsonArrayBuilder.build();
    return Response.ok(jsonArray.toString()).build();

}

From source file:com.adobe.cq.wcm.core.components.internal.models.v1.ImageImpl.java

protected void buildJson() {
    JsonArrayBuilder smartSizesJsonBuilder = Json.createArrayBuilder();
    for (int size : smartSizes) {
        smartSizesJsonBuilder.add(size);
    }/* w w w. jav  a2  s  .co m*/
    JsonArrayBuilder smartImagesJsonBuilder = Json.createArrayBuilder();
    for (String image : smartImages) {
        smartImagesJsonBuilder.add(image);
    }
    JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    jsonObjectBuilder.add(JSON_SMART_IMAGES, smartImagesJsonBuilder);
    jsonObjectBuilder.add(JSON_SMART_SIZES, smartSizesJsonBuilder);
    jsonObjectBuilder.add(JSON_LAZY_ENABLED, !disableLazyLoading);
    json = jsonObjectBuilder.build().toString();
}

From source file:org.bsc.confluence.rest.AbstractRESTConfluenceService.java

/**
 *
 * @param inputData//ww  w .  j av a 2  s  . c om
 * @return
 */
protected final void rxAddLabels(String id, String... labels) {

    final JsonArrayBuilder inputBuilder = Json.createArrayBuilder();

    for (String name : labels) {

        inputBuilder.add(Json.createObjectBuilder().add("prefix", "global").add("name", name));

    }

    final JsonArray inputData = inputBuilder.build();

    final MediaType storageFormat = MediaType.parse("application/json");

    final RequestBody inputBody = RequestBody.create(storageFormat, inputData.toString());

    final HttpUrl url = urlBuilder().addPathSegment("content").addPathSegment(id).addPathSegment("label")
            .build();

    fromUrlPOST(url, inputBody, "add label");
}

From source file:org.openlmis.converter.StandardArrayTypeConverter.java

@Override
public void convert(JsonObjectBuilder builder, Mapping mapping, String value) {
    BaseCommunicationService service = services.getService(mapping.getEntityName());

    List<String> values = getArrayValues(value);
    String by = getBy(mapping.getType());

    JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();

    for (String v : values) {
        JsonObject object = service.findBy(by, v);

        if (null == object) {
            logger.warn("The CSV file contained reference to entity {} "
                    + "with {} {} but such reference does not exist.", mapping.getEntityName(), by, v);
        } else {/*from  w  w w. j a va  2s  . com*/
            arrayBuilder.add(object);
        }
    }

    builder.add(mapping.getTo(), arrayBuilder);
}

From source file:edu.harvard.iq.dataverse.mydata.MyDataFilterParams.java

/**
* "publication_statuses" : [ name 1, name 2, etc.]
* 
* @return //from  ww  w .  ja  va  2  s  .c o m
*/
public JsonArrayBuilder getListofSelectedPublicationStatuses() {

    JsonArrayBuilder jsonArray = Json.createArrayBuilder();

    for (String pubStatus : this.publicationStatuses) {
        jsonArray.add(pubStatus);
    }
    return jsonArray;

}

From source file:searcher.CollStat.java

public String constructJSONForRetrievedSet(IndexReader reader, Query q, ScoreDoc[] hits) throws Exception {
    JsonArrayBuilder arrayBuilder = factory.createArrayBuilder();

    for (ScoreDoc hit : hits) {
        arrayBuilder.add(constructJSONForDoc(reader, q, hit.doc));
    }//from ww  w.  j  a  va  2  s .c om
    return arrayBuilder.build().toString();
}

From source file:org.hyperledger.fabric_ca.sdk.HFCAIdentity.java

private JsonObject idToJsonObject() {
    JsonObjectBuilder ob = Json.createObjectBuilder();
    ob.add("id", enrollmentID);
    ob.add("type", type);
    if (null != maxEnrollments) {
        ob.add("max_enrollments", maxEnrollments);
    }/*w w w .j av a  2s . com*/
    if (affiliation != null) {
        ob.add("affiliation", affiliation);
    }
    JsonArrayBuilder ab = Json.createArrayBuilder();
    for (Attribute attr : attrs) {
        ab.add(attr.toJsonObject());
    }
    ob.add("attrs", ab.build());
    if (this.secret != null) {
        ob.add("secret", secret);
    }
    if (client.getCAName() != null) {
        ob.add(HFCAClient.FABRIC_CA_REQPROP, client.getCAName());
    }
    return ob.build();
}