title: Jackson: Check if ArrayNode contains JsonNode
body: <p>I am using the <a href="https://github.com/FasterXML/jackson" rel="noreferrer">Jackson</a> JSON library and its <em>Tree Model</em> system (<code>JsonNode</code>) in my Java application. In this, I need to check if an <code>ArrayNode</code> contains a given <code>JsonNode</code>. I was looking through the JavaDocs and I did not see any sort of <code>.contains()</code> method for <code>ArrayNode</code>. I ended up writing a contains methods myself:</p>
  
  <pre><code>   public static boolean arrayNodeContains(ArrayNode arrayNode, JsonNode node) {
        Stream&lt;JsonNode&gt; nodeStream = StreamSupport.stream(arrayNode.spliterator(), false);
        return nodeStream.anyMatch(j -&gt; j.equals(node));
     }
  </code></pre>
  
  <p>Unit Test:</p>
  
  <pre><code>   @Test
     public void testArrayNodeContains()
           throws IOException
     {
        ObjectMapper mapper = new ObjectMapper;
  
        String arrayJsonString = "[{\"foo\":\"bar\"},{\"foo\":\"baz\"},{\"baz\":\"bar\"}]";
        String nodeTrueJsonString = "{\"foo\":\"bar\"}";
        String nodeFalseJsonString = "{\"foo\":\"brains\"}";
        List&lt;Object&gt; list = mapper.readValue(arrayJsonString, List.class);
        ArrayNode arrayNode = mapper.valueToTree(list);
  
        Map&lt;String, Object&gt; nodeTrueMap = mapper.readValue(nodeTrueJsonString, Map.class);
        JsonNode nodeTrue = mapper.valueToTree(nodeTrueMap);
  
        assertTrue(arrayNodeContains(arrayNode, nodeTrue));
  
        Map&lt;String, Object&gt; nodeFalseMap = mapper.readValue(nodeFalseJsonString, Map.class);
        JsonNode nodeFalse = mapper.valueToTree(nodeFalseMap);
        assertFalse(arrayNodeContains(arrayNode, nodeFalse));
     }
  </code></pre>
  
  <p>Did I miss something in Jackson and I am duplicating some library method I missed. Otherwise, is there a better way of doing this than what I did?</p>