title: Spring MockMvc: Assert Json field is either an empty array or not existed
body: <p>I'm using <a href="https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/test/web/servlet/MockMvc.html" rel="nofollow noreferrer">MockMvc</a> to test an API which returns JSON content, and that JSON may contain a field called <strong>shares</strong> as an empty array, or may not be existed at all (I mean <strong>shares</strong> field).</p>
  
  <p>JSON sample:</p>
  
  <pre><code>{
      "id":1234,
       .....
      "shares":[]
  }
  
  //or
  
  {
      "id":1234,
      ....
  }
  </code></pre>
  
  <p>How can I assert that this field is either empty or not existed</p>
  
  <p>like:</p>
  
  <pre><code>mvc.perform(
      post("....url.......")
          .andExpect(status().is(200))
          // I need one of the following to be true, but this code will assert both of them, so it will fail
          .andExpect(jsonPath("$.shares").isEmpty())
          .andExpect(jsonPath("$.shares").doesNotExist())
  </code></pre>