Example usage for javax.json JsonArray toString

List of usage examples for javax.json JsonArray toString

Introduction

In this page you can find the example usage for javax.json JsonArray toString.

Prototype

@Override
String toString();

Source Link

Document

Returns JSON text for this JSON value.

Usage

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  . ja  v  a2 s.  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.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// ww  w  .  j  a v a  2 s  .  co 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:org.hyperledger.fabric.sdk.ChaincodeCollectionConfiguration.java

/**
 * Creates a new ChaincodeCollectionConfiguration instance configured with details supplied in a JSON object
 *
 * @param jsonConfig JSON object containing network configuration details
 * @return A new ChaincodeCollectionConfiguration instance
 * @throws InvalidArgumentException/*from   w ww. ja va 2 s .c o  m*/
 */
public static ChaincodeCollectionConfiguration fromJsonObject(JsonArray jsonConfig)
        throws InvalidArgumentException, ChaincodeCollectionConfigurationException {

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

    if (logger.isTraceEnabled()) {
        logger.trace(format("ChaincodeCollectionConfiguration.fromJsonObject: %s", jsonConfig.toString()));
    }

    return load(jsonConfig);
}