Example usage for com.fasterxml.jackson.databind JsonNode spliterator

List of usage examples for com.fasterxml.jackson.databind JsonNode spliterator

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind JsonNode spliterator.

Prototype

default Spliterator<T> spliterator() 

Source Link

Document

Creates a Spliterator over the elements described by this Iterable .

Usage

From source file:org.hawkular.services.rest.test.InventoryHelper.java

static List<ExtendedInventoryStructure> extractStructuresFromResponse(JsonNode response) {
    return StreamSupport.stream(response.spliterator(), true).map(node -> node.get("data"))
            .map(InventoryHelper::rebuildFromChunks).filter(Optional::isPresent).map(Optional::get)
            .collect(Collectors.toList());
}

From source file:net.hamnaberg.json.Query.java

static List<Query> fromArray(JsonNode queries) {
    return Collections.unmodifiableList(StreamSupport.stream(queries.spliterator(), false)
            .map(jsonNode -> new Query((ObjectNode) jsonNode)).collect(Collectors.toList()));
}

From source file:net.hamnaberg.json.Link.java

static List<Link> fromArray(JsonNode node) {
    return Collections.unmodifiableList(StreamSupport.stream(node.spliterator(), false)
            .map(jsonNode -> new Link((ObjectNode) jsonNode)).collect(Collectors.toList()));
}

From source file:com.company.et.service.JsonService.java

/**
 *  ??  Json'a   ?-json'//from ww  w  .  j a v  a  2  s .c o  m
 * @param jsonArray
 * @return ??  ? Json
 * @throws IOException 
 */
public static List<String> split(final String jsonArray) throws IOException {
    final JsonNode jsonNode = new ObjectMapper().readTree(jsonArray);
    return StreamSupport.stream(jsonNode.spliterator(), false).map(JsonNode::toString)
            .collect(Collectors.toList());
}

From source file:net.hamnaberg.json.Property.java

public static List<Property> fromData(JsonNode data) {
    return unmodifiableList(stream(data.spliterator(), false)
            .map(jsonNode -> new Property((ObjectNode) jsonNode)).collect(Collectors.toList()));
}

From source file:net.hamnaberg.json.Item.java

static List<Item> fromArray(JsonNode queries) {
    return Collections.unmodifiableList(StreamSupport.stream(queries.spliterator(), false)
            .map(query -> new Item((ObjectNode) query)).collect(Collectors.toList()));
}

From source file:org.n52.iceland.config.json.AbstractJsonDao.java

protected Stream<JsonNode> createStream(JsonNode node) {
    return StreamSupport.stream(node.spliterator(), false);
}

From source file:io.github.azige.moebooruviewer.MoebooruAPITest.java

@Test
public void testListPostsOrder() throws IOException {
    String resourceName = "/postV2_limit100.json";
    byte[] resourceBytes;
    {/* w  ww  . j  a  va2  s  .c  om*/
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        try (InputStream input = getClass().getResourceAsStream(resourceName)) {
            IOUtils.copy(input, output);
        }
        resourceBytes = output.toByteArray();
    }
    when(netIO.download("http://yande.re/post.json?api_version=2&include_pools=1&page=1&limit=100&tags="))
            .thenReturn(resourceBytes);

    List<Post> posts = mapi.listPosts(1, 100);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode postNode = mapper.readTree(getClass().getResourceAsStream(resourceName)).get("posts");

    List<Integer> originalIdList = StreamSupport.stream(postNode.spliterator(), false)
            .map(node -> node.get("id").asInt()).collect(Collectors.toList());
    List<Integer> convertedIdList = posts.stream().map(post -> post.getId()).collect(Collectors.toList());
    assertThat(convertedIdList, is(equalTo(originalIdList)));
}

From source file:com.ikanow.aleph2.data_import_manager.harvest.modules.LocalHarvestTestModule.java

private static DataBucketBean createBucketFromSource(JsonNode src_json) throws Exception {

    @SuppressWarnings("unused")
    final String _id = safeJsonGet(JsonUtils._ID, src_json).asText(); // (think we'll use key instead of _id?)
    final String key = safeJsonGet("key", src_json).asText();
    final String created = safeJsonGet("created", src_json).asText();
    final String modified = safeJsonGet("modified", src_json).asText();
    final String title = safeJsonGet("title", src_json).asText();
    final String description = safeJsonGet("description", src_json).asText();
    final String owner_id = safeJsonGet("ownerId", src_json).asText();

    final JsonNode tags = safeJsonGet("tags", src_json); // collection of strings
    //TODO (ALEPH-19): need to convert the DB authentication across to the Aleph2 format 
    @SuppressWarnings("unused")
    final JsonNode comm_ids = safeJsonGet("communityIds", src_json); // collection of strings
    final JsonNode px_pipeline = safeJsonGet("processingPipeline", src_json); // collection of JSON objects, first one should have data_bucket
    final JsonNode px_pipeline_first_el = px_pipeline.get(0);
    final JsonNode data_bucket = safeJsonGet("data_bucket", px_pipeline_first_el);

    final DataBucketBean bucket = BeanTemplateUtils.build(data_bucket, DataBucketBean.class)
            .with(DataBucketBean::_id, key).with(DataBucketBean::created, parseJavaDate(created))
            .with(DataBucketBean::modified, parseJavaDate(modified)).with(DataBucketBean::display_name, title)
            .with(DataBucketBean::description, description).with(DataBucketBean::owner_id, owner_id)
            .with(DataBucketBean::tags, StreamSupport.stream(tags.spliterator(), false).map(jt -> jt.asText())
                    .collect(Collectors.toSet()))
            .done().get();/*from  w  ww .java 2 s . c om*/

    return bucket;
}

From source file:org.openmhealth.shim.withings.mapper.WithingsBodyMeasureDataPointMapper.java

/**
 * @param measuresNode the list of measures in a measure group node
 * @param bodyMeasureType the measure type of interest
 * @return the value of the specified measure type, if present
 *//*from   w w  w  .  jav  a2  s .co  m*/
protected Optional<BigDecimal> getValueForMeasureType(JsonNode measuresNode,
        WithingsBodyMeasureType bodyMeasureType) {

    List<BigDecimal> values = StreamSupport.stream(measuresNode.spliterator(), false)
            .filter((measureNode) -> asRequiredLong(measureNode, "type") == bodyMeasureType.getMagicNumber())
            .map(this::getValue).collect(Collectors.toList());

    if (values.isEmpty()) {
        return Optional.empty();
    }

    if (values.size() > 1) {
        throw new JsonNodeMappingException(
                format("The following Withings measures node contains multiple measures of type %s.\n%s.",
                        bodyMeasureType, measuresNode));
    }

    return Optional.of(values.get(0));
}