Package com.fasterxml.jackson.databind.node

Examples of com.fasterxml.jackson.databind.node.ArrayNode


   
    // Make sure it is a JSON array.
    if(! (dataNode instanceof ArrayNode)) {
      throw new OmhException("The data was not a JSON array.");
    }
    ArrayNode dataArray = (ArrayNode) dataNode;
   
    // Get the number of data points.
    int numDataPoints = dataArray.size();
   
    // Create the result list of data points.
    List<Data> dataPoints = new ArrayList<Data>(numDataPoints);
   
    // Create a new ObjectMapper that will be used to convert the meta-data
    // node into a MetaData object.
    ObjectMapper mapper = new ObjectMapper();
   
    // For each element in the array, be sure it is a JSON object that
    // represents a valid data point for this schema.
    for(int i = 0; i < numDataPoints; i++) {
      // Get the current data point.
      JsonNode dataPoint = dataArray.get(i);
     
      // Validate that it is a JSON object.
      if(! (dataPoint instanceof ObjectNode)) {
        throw
          new OmhException(
View Full Code Here


    MapReduce.Response response = client.execute(mr);
   
        // The query should return one phase result which is a JSON array containing a
    // single JSON object that is a set of word counts.       
        ArrayNode resultList = response.getResultForPhase(1);

    assertEquals(1, response.getResultsFromAllPhases().size());
       
    String json = resultList.get(0).toString();
    ObjectMapper oMapper = new ObjectMapper();
       
        TypeReference<Map<String,Integer>> type = new TypeReference<Map<String,Integer>>(){};
        Map<String, Integer> resultMap = oMapper.readValue(json, type);
View Full Code Here

                .build();
       
        cluster.execute(mrOp);
        mrOp.await();
        assertTrue(mrOp.isSuccess());
        ArrayNode resultList = mrOp.get().getResults().get(1);
       
        // The query should return one result which is a JSON array containing a
        // single JSON object that is a asSet of word counts.
        assertEquals(resultList.size(), 1);
       
        String json = resultList.get(0).toString();
        ObjectMapper oMapper = new ObjectMapper();
        @SuppressWarnings("unchecked")
        Map<String, Integer> resultMap = oMapper.readValue(json, Map.class);
       
        assertNotNull(resultMap.containsKey("the"));
View Full Code Here

    return json;
  }

  public String updateMLS(String instCode, Collection<ObjectNode> accns) throws GenesysApiException {

    ArrayNode arr = mapper.createArrayNode();
    for (ObjectNode accn : accns) {
      arr.add(accn);
    }

    _log.debug("Sending: " + arr);
    return query(Verb.PUT, "/acn/" + instCode + "/update", null, arr.toString());
  }
View Full Code Here

    _log.debug("Sending: " + arr);
    return query(Verb.PUT, "/acn/" + instCode + "/update", null, arr.toString());
  }

  public String accessionExists(String instCode, Collection<ObjectNode> accns) throws GenesysApiException {
    ArrayNode arr = mapper.createArrayNode();
    for (ObjectNode accn : accns) {
      arr.add(accn);
    }

    _log.debug("Sending: " + arr);
    return query(Verb.PUT, "/acn/" + instCode + "/check", null, arr.toString());
  }
View Full Code Here

    if (accns == null || accns.size() == 0) {
      return null;
    }

    ArrayNode arr = mapper.createArrayNode();
    for (ObjectNode accn : accns) {
      arr.add(accn);
    }

    return updateAccessions(instCode, arr);
  }
View Full Code Here

    System.out.println("Done editing " + label);
  }

  private void updateJsonArray(String label, ArrayNode n) {
    System.out.println("Array: " + n);
    ArrayNode na = n.arrayNode();
    String val;
    do {
      val = in.nextLine().trim();
      if (val.startsWith("i ")) {
        na.add(Integer.parseInt(val.substring(2)));
      } else if (val.startsWith("d ")) {
        na.add(Double.parseDouble(val.substring(2)));
      } else if (val.startsWith("o ")) {
        try {
          Object o = Class.forName("org.genesys2.client.rest.model." + val.substring(2)).newInstance();
          JsonNode newNode = mapper.readTree(mapper.writeValueAsString(o));
          System.out.println(newNode);
          updateJsonObject(label + "." + val.substring(2), newNode);
          na.add(newNode);
        } catch (ClassNotFoundException e) {
          System.err.println(e.getMessage());
        } catch (JsonProcessingException e) {
          System.err.println(e.getMessage());
        } catch (IOException e) {
          System.err.println(e.getMessage());
        } catch (InstantiationException e) {
          System.err.println(e.getMessage());
        } catch (IllegalAccessException e) {
          System.err.println(e.getMessage());
        }
      } else if (StringUtils.isBlank(val)) {
        break;
      } else {
        na.add(val);
      }
    } while (StringUtils.isNotBlank(val));
    n.removeAll();
    n.addAll(na);
    System.out.println("Done editing array " + label);
View Full Code Here

    if (StringUtils.equals(newRules, rules)) {
      System.out.println("No change.");
      return;
    }

    ArrayNode arr;
    try {
      arr = (ArrayNode) mapper.readTree(newRules);
    } catch (Throwable e) {
      System.err.println(e.getMessage());
      return;
    }

    System.out.println(arr.toString());
    // make a crop
    System.out.println("New rules: " + genesysClient.query(Verb.POST, "/crops/" + shortName + "/rules", null, arr.toString()));
  }
View Full Code Here

                PagingResult<T> result = new PagingResult<>();
                JsonNode node = mapper.readTree(response.getEntity().getContent());
                if (node.get("total_rows") != null) {
                    result.setTotalRows(node.get("total_rows").asInt());
                }
                ArrayNode rowsNode = (ArrayNode) node.get("rows");
                for (JsonNode aRowsNode : rowsNode) {
                    if (aRowsNode.has("doc")) {
                        result.add(mapper.<T>readValue(aRowsNode.get("doc").toString(), clazz));
                    }
                }
View Full Code Here

                PagingResult<T> result = new PagingResult<>();
                JsonNode node = mapper.readTree(response.getEntity().getContent());
                if (node.get("total_rows") != null) {
                    result.setTotalRows(node.get("total_rows").asInt());
                }
                ArrayNode rowsNode = (ArrayNode) node.get("rows");
                for (JsonNode aRowsNode : rowsNode) {
                    JsonNode valueNode = aRowsNode.has("doc") ? aRowsNode.get("doc") : aRowsNode.get("value");
                    if (!clazz.getName().equals(String.class.getName())) {
                        result.add((T) jsonReader.readValue(valueNode));
                    } else {
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.node.ArrayNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.