Package com.fasterxml.jackson.databind.node

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


    public void matcherShouldPassWhenRequiredElementMatches() {
        assertThat(matcher.matches(array("foo", "bar")), is(true));
    }
   
    private ArrayNode array(String... items) {
        ArrayNode array = MAPPER.createArrayNode();
        for (String item : items) {
            array.add(item);
        }
        return array;
    }
View Full Code Here


        node.put(name, value);
        return node;
    }
   
    private ArrayNode array(String... items) {
        ArrayNode node = MAPPER.createArrayNode();
        for (String item : items) {
            node.add(item);
        }
        return node;
    }
View Full Code Here

    public void matcherShouldPassWhenMatcherMatches() {
        assertThat(matcher.matches(array("foobar", "enjoyment")), is(true));
    }
   
    private ArrayNode array(String... items) {
        ArrayNode array = MAPPER.createArrayNode();
        for (String item : items) {
            array.add(item);
        }
        return array;
    }
View Full Code Here

            ObjectNode stockUpdateMessage = Json.newObject();
            stockUpdateMessage.put("type", "stockhistory");
            stockUpdateMessage.put("symbol", stockHistory.symbol());

            ArrayNode historyJson = stockUpdateMessage.putArray("history");
            for (Object price : stockHistory.history()) {
                historyJson.add(((Number)price).doubleValue());
            }
           
            out.write(stockUpdateMessage);
        }
    }
View Full Code Here

      for (String soneId : soneIds) {
        /* just add it, we skip null further down. */
        sones.add(webInterface.getCore().getSone(soneId).orNull());
      }
    }
    ArrayNode jsonSones = new ArrayNode(instance);
    for (Sone sone : sones) {
      if (sone == null) {
        continue;
      }
      jsonSones.add(createJsonSone(sone));
    }
    /* load notifications. */
    List<Notification> notifications = ListNotificationFilters.filterNotifications(webInterface.getNotifications().getNotifications(), currentSone);
    Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
    /* load new posts. */
    Collection<Post> newPosts = webInterface.getNewPosts();
    if (currentSone != null) {
      newPosts = Collections2.filter(newPosts, new Predicate<Post>() {

        @Override
        public boolean apply(Post post) {
          return ListNotificationFilters.isPostVisible(currentSone, post);
        }

      });
    }
    ArrayNode jsonPosts = new ArrayNode(instance);
    for (Post post : newPosts) {
      ObjectNode jsonPost = new ObjectNode(instance);
      jsonPost.put("id", post.getId());
      jsonPost.put("sone", post.getSone().getId());
      jsonPost.put("recipient", post.getRecipientId().orNull());
      jsonPost.put("time", post.getTime());
      jsonPosts.add(jsonPost);
    }
    /* load new replies. */
    Collection<PostReply> newReplies = webInterface.getNewReplies();
    if (currentSone != null) {
      newReplies = Collections2.filter(newReplies, new Predicate<PostReply>() {

        @Override
        public boolean apply(PostReply reply) {
          return ListNotificationFilters.isReplyVisible(currentSone, reply);
        }

      });
    }
    /* remove replies to unknown posts. */
    newReplies = Collections2.filter(newReplies, PostReply.HAS_POST_FILTER);
    ArrayNode jsonReplies = new ArrayNode(instance);
    for (PostReply reply : newReplies) {
      ObjectNode jsonReply = new ObjectNode(instance);
      jsonReply.put("id", reply.getId());
      jsonReply.put("sone", reply.getSone().getId());
      jsonReply.put("post", reply.getPostId());
      jsonReply.put("postSone", reply.getPost().get().getSone().getId());
      jsonReplies.add(jsonReply);
    }
    return createSuccessJsonObject().put("loggedIn", currentSone != null).put("options", createJsonOptions(currentSone)).put("sones", jsonSones).put("notificationHash", notifications.hashCode()).put("newPosts", jsonPosts).put("newReplies", jsonReplies);
  }
View Full Code Here

  protected JsonReturnObject createJsonObject(FreenetRequest request) {
    Sone currentSone = getCurrentSone(request.getToadletContext(), false);
    Collection<Notification> notifications = webInterface.getNotifications().getNotifications();
    List<Notification> filteredNotifications = ListNotificationFilters.filterNotifications(notifications, currentSone);
    Collections.sort(filteredNotifications, Notification.CREATED_TIME_SORTER);
    ArrayNode jsonNotifications = new ArrayNode(instance);
    for (Notification notification : filteredNotifications) {
      jsonNotifications.add(createJsonNotification(request, notification));
    }
    return createSuccessJsonObject().put("notificationHash", filteredNotifications.hashCode()).put("notifications", jsonNotifications).put("options", createJsonOptions(currentSone));
  }
View Full Code Here

   * @param sones
   *            The Sones to convert to an array
   * @return The Sones, sorted by name
   */
  private static JsonNode getSones(Set<Sone> sones) {
    ArrayNode soneArray = new ArrayNode(instance);
    for (Sone sone : FluentIterable.from(sones).toSortedList(NICE_NAME_COMPARATOR)) {
      soneArray.add(new ObjectNode(instance).put("id", sone.getId()).put("name", SoneAccessor.getNiceName(sone)));
    }
    return soneArray;
  }
View Full Code Here

                if (moreParts) {
                    child = child.get(index);
                    node = child;
                }
                else {
                    ArrayNode array = (ArrayNode)child;
                    array.set(index, TextNode.valueOf(value));
                    return;
                }
            }
            else if (moreParts) {
                child = obj.get(key);
                if (child == null) {
                    child = obj.objectNode();
                    obj.set(key, child);
                }
                if (child.isArray()) {
                    throw new IllegalArgumentException("Unable to override " + name + "; target is an array but no index specified");
                }
                node = child;
            }

            if (!moreParts) {
                if (node.get(key) != null && node.get(key).isArray()) {
                    ArrayNode arrayNode = (ArrayNode) obj.get(key);
                    arrayNode.removeAll();
                    Pattern escapedComma = Pattern.compile("\\\\,");
                    for (String val : Splitter.on(Pattern.compile("(?<!\\\\),")).trimResults().split(value)) {
                        arrayNode.add(escapedComma.matcher(val).replaceAll(","));
                    }
                }
                else {
                    obj.put(key, value);
                }
View Full Code Here

   
    if(last instanceof PartsLexer.ArrayField){
      PartsLexer.ArrayField arr = (PartsLexer.ArrayField)last;
      int index = arr.arrayIndex;
      root = root.path(last.getName());
      ArrayNode arrNode = (ArrayNode)root;
      if(arrNode.size()<=index){
        arrNode.add(data);
      }else{
        arrNode.set(index, data);
      }
      return root;
     
    }else{
      try{
View Full Code Here

 
  protected JsonNode updatePayloadFieldValue(String sPayload, String sFieldName, String[] values)
  {
    JsonNode node = getPayload(sPayload);
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode array = mapper.valueToTree(Arrays.asList(values));
    ((ObjectNode)node).putArray(sFieldName).addAll(array);
    return node;
  }
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.