Example usage for javax.json JsonArray size

List of usage examples for javax.json JsonArray size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of elements in this list.

Usage

From source file:com.buffalokiwi.aerodrome.jet.orders.OrderItemRec.java

/**
 * Turn some fee adjustment data from jet json into FeeAdjRec instances..
 * @param a data /*from  w w  w .j  a v  a2 s  . c  om*/
 * @return adjustments
 * @throws JetException 
 */
private static List<FeeAdjRec> jsonToFeeAdj(final JsonArray a) throws JetException {
    final List<FeeAdjRec> adj = new ArrayList<>();

    if (a == null)
        return adj;

    for (int i = 0; i < a.size(); i++) {
        try {
            adj.add(FeeAdjRec.fromJson(a.getJsonObject(i)));
        } catch (Exception e) {
            APILog.error(LOG, e, "Failed to build FeeAdjRec instance at position", String.valueOf(i));
            throw new JetException("Failed to build FeeAdjRec", e);
        }
    }

    return adj;
}

From source file:com.dhenton9000.jersey.client.BasicTests.java

@Test
public void testConfigReponseFilter() {
    ClientConfig config = new ClientConfig();
    config.register(ResponseFilter.class);
    Client client = ClientBuilder.newClient(config);
    WebTarget target = client.target(getBaseURI());
    Response response = target.path("restaurant").request().accept(MediaType.APPLICATION_JSON)
            .get(Response.class);
    if (response.getStatus() != 200) {
        fail("status problem for request " + response.getStatus());
    }//from  ww  w.j ava2 s .  c  om

    InputStream jsonStringResponse = response.readEntity(InputStream.class);
    JsonReader myreader = Json.createReader(jsonStringResponse);
    JsonArray restaurants = myreader.readArray();
    assertTrue(restaurants.size() > 5);
    assertTrue(ResponseFilter.gotHit);
    ResponseFilter.gotHit = false;

}

From source file:com.dhenton9000.jersey.client.BasicTests.java

/**
 * this demonstrates writing headers to the request
 *//*from  w ww.  ja  v  a 2s. c  om*/
@Test
public void testConfigRequestFilter() {
    ClientConfig config = new ClientConfig();
    config.register(RequestFilter.class);
    Client client = ClientBuilder.newClient(config);
    WebTarget target = client.target(getBaseURI());
    Response response = target.path("restaurant").request().accept(MediaType.APPLICATION_JSON)
            .get(Response.class);
    if (response.getStatus() != 200) {
        fail("status problem for request " + response.getStatus());
    }

    InputStream jsonStringResponse = response.readEntity(InputStream.class);
    JsonReader myreader = Json.createReader(jsonStringResponse);
    JsonArray restaurants = myreader.readArray();
    assertTrue(restaurants.size() > 5);
    assertTrue(RequestFilter.gotHit);
    RequestFilter.gotHit = false;

}

From source file:org.kitodo.data.elasticsearch.index.type.AuthorityTypeTest.java

@Test
public void shouldCreateSecondDocument() throws Exception {
    AuthorityType authorityType = new AuthorityType();

    Authority authority = prepareData().get(1);
    HttpEntity document = authorityType.createDocument(authority);

    JsonObject actual = Json.createReader(new StringReader(EntityUtils.toString(document))).readObject();

    assertEquals("Key title doesn't match to given value!", "Second",
            AuthorityTypeField.TITLE.getStringValue(actual));

    JsonArray userGroups = AuthorityTypeField.USER_GROUPS.getJsonArray(actual);
    assertEquals("Size userGroups doesn't match to given value!", 0, userGroups.size());
}

From source file:org.kitodo.data.elasticsearch.index.type.AuthorityTypeTest.java

@Test
public void shouldCreateFirstDocument() throws Exception {
    AuthorityType authorityType = new AuthorityType();

    Authority authority = prepareData().get(0);
    HttpEntity document = authorityType.createDocument(authority);

    JsonObject actual = Json.createReader(new StringReader(EntityUtils.toString(document))).readObject();

    assertEquals("Key title doesn't match to given value!", "First",
            AuthorityTypeField.TITLE.getStringValue(actual));

    JsonArray userGroups = actual.getJsonArray(AuthorityTypeField.USER_GROUPS.getKey());
    assertEquals("Size userGroups doesn't match to given value!", 1, userGroups.size());

    JsonObject userGroup = userGroups.getJsonObject(0);
    assertEquals("Key userGroups.id doesn't match to given value!", 1,
            UserGroupTypeField.ID.getIntValue(userGroup));
    assertEquals("Key userGroups.title doesn't match to given value!", "First",
            UserGroupTypeField.TITLE.getStringValue(userGroup));
}

From source file:joachimeichborn.geotag.geocode.GoogleGeocoder.java

private Geocoding extractLocationInformation(final JsonObject aJsonRepresentation) {
    final JsonArray results = aJsonRepresentation.getJsonArray("results");
    logger.fine("Found " + String.valueOf(results.size()) + " entries");

    return createTextualRepresentation(results);
}

From source file:ro.cs.products.landsat.LandsatSearch.java

public List<ProductDescriptor> execute() throws IOException {
    List<ProductDescriptor> results = new ArrayList<>();
    String queryUrl = getQuery();
    Logger.getRootLogger().info(queryUrl);
    try (CloseableHttpResponse response = NetUtils.openConnection(queryUrl, credentials)) {
        switch (response.getStatusLine().getStatusCode()) {
        case 200:
            String body = EntityUtils.toString(response.getEntity());
            final JsonReader jsonReader = Json.createReader(new StringReader(body));
            Logger.getRootLogger().debug("Parsing json response");
            JsonObject responseObj = jsonReader.readObject();
            JsonArray jsonArray = responseObj.getJsonArray("results");
            for (int i = 0; i < jsonArray.size(); i++) {
                LandsatProductDescriptor currentProduct = new LandsatProductDescriptor();
                JsonObject result = jsonArray.getJsonObject(i);
                currentProduct.setName(result.getString("scene_id"));
                currentProduct.setId(result.getString("sceneID"));
                currentProduct.setPath(String.valueOf(result.getInt("path")));
                currentProduct.setRow(String.valueOf(result.getInt("row")));
                currentProduct.setSensingDate(result.getString("acquisitionDate"));
                results.add(currentProduct);
            }//from   w  w w  .  ja v  a  2  s.  co m

            break;
        case 401:
            Logger.getRootLogger().info("The supplied credentials are invalid!");
            break;
        default:
            Logger.getRootLogger().info("The request was not successful. Reason: %s",
                    response.getStatusLine().getReasonPhrase());
            break;
        }
    }
    Logger.getRootLogger().info("Query returned %s products", results.size());
    return results;
}

From source file:com.rhcloud.javaee.movieinfo.business.actor.boundry.ActorResourceIT.java

@Test
public void get_all_actors() {

    Response getResponse = null;// w ww. j a  v  a  2 s .co m

    try {
        getResponse = provider.target().path("/" + ACTORS_PATH).request(APPLICATION_JSON).get();
    } finally {
        System.out.println("Server responded ? " + (getResponse != null));
        assumeThat(getResponse, is(notNullValue()));
    }

    assertThat(getResponse, is(successful()));
    assertThat(getResponse.hasEntity(), is(true));

    JsonArray payload = getResponse.readEntity(JsonArray.class);
    assertThat(payload, is(notNullValue()));
    final int size = payload.size();
    assertThat(size, is(not(0)));

    JsonObject value = payload.getJsonObject(size - 1);
    assertThat(value, is(notNullValue()));
    assertThat(value.getInt("id") >= size, is(true));
}

From source file:io.bibleget.BibleGetAbout.java

private void prepareDynamicInformation() throws ClassNotFoundException {
    bibleGetDB = BibleGetDB.getInstance();
    jList1 = new VersionsSelect();
    versionLangs = jList1.getVersionLangs();
    versionCount = jList1.getVersionCount();

    String langsSupported;/*w w w  .  j a  v  a2s .  c  o  m*/
    List<String> langsLocalized = new ArrayList<>();
    booksLangs = 0;
    booksStr = "";
    if (bibleGetDB != null) {
        //System.out.println("oh good, biblegetDB is not null!");
        langsSupported = bibleGetDB.getMetaData("LANGUAGES");
        //System.out.println(langsSupported);
        JsonReader jsonReader = Json.createReader(new StringReader(langsSupported));
        JsonArray bibleVersionsObj = jsonReader.readArray();
        booksLangs = bibleVersionsObj.size();
        for (JsonValue jsonValue : bibleVersionsObj) {
            //System.out.println(jsonValue.toString());
            langsLocalized.add(BibleGetI18N.localizeLanguage(jsonValue.toString()));
        }
        booksStr = StringUtils.join(langsLocalized, ", ");
    } else {
        //System.out.println("Looks like biblegetDB is null :/");
    }

}

From source file:com.buffalokiwi.aerodrome.jet.orders.OrderRec.java

/**
 * Turn Jet Json into an OrderRec/*from   w w  w .  j  a  v a2 s . c  o  m*/
 * @param json Jet json
 * @return object 
 */
public static OrderRec fromJson(final JsonObject json) {
    Utils.checkNull(json, "json");
    final Builder b = new Builder().setMerchantOrderId(json.getString("merchant_order_id", ""))
            .setReferenceOrderId(json.getString("reference_order_id", ""))
            .setCustomerReferenceOrderId(json.getString("customer_reference_order_id", ""))
            .setFulfillmentNode(json.getString("fulfillment_node", ""))
            .setAltOrderId(json.getString("alt_order_id", "")).setHashEmail(json.getString("hash_email", ""))
            .setStatus(OrderStatus.fromText(json.getString("status", "")))
            .setExceptionState(OrderExceptionState.fromText(json.getString("exception_state", "")))
            .setOrderPlacedDate(JetDate.fromJetValueOrNull(json.getString("order_placed_date", "")))
            .setOrderTransmissionDate(JetDate.fromJetValueOrNull(json.getString("order_transmission_date", "")))
            .setJetRequestDirectedCancel(json.getBoolean("jet_requested_directed_cancel", false))
            .setOrderReadyDate(JetDate.fromJetValueOrNull(json.getString("order_ready_date", "")))
            .setHasShipments(json.getBoolean("has_shipments", false))
            .setOrderAckDate(JetDate.fromJetValueOrNull(json.getString("order_acknowledge_date", "")))
            .setAckStatus(AckStatus.fromText(json.getString("acknowledgement_status", "")));

    buildOrderDetail(b, json.getJsonObject("order_detail"));
    buildBuyer(b, json.getJsonObject("buyer"));
    buildShipTo(b, json.getJsonObject("shipping_to"));
    buildOrderTotals(b, json.getJsonObject("order_totals"));

    try {
        buildOrderItems(b, json.getJsonArray("order_items"));
    } catch (JetException e) {
        APILog.error(LOG, e, "Failed to generate order items");
    }

    //..Build the shipments
    final JsonArray shipments = json.getJsonArray("shipments");
    if (shipments != null) {
        for (int i = 0; i < shipments.size(); i++) {
            final JsonObject shipment = shipments.getJsonObject(i);
            if (shipment == null)
                continue;

            b.getShipments().add(ShipmentRec.fromJson(shipment));
        }
    }

    return new OrderRec(b);
}